mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 21:40:23 +01:00
83 lines
2.3 KiB
R
83 lines
2.3 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/REDCap_split.r
|
|
\name{REDCap_split}
|
|
\alias{REDCap_split}
|
|
\title{Split REDCap repeating instruments table into multiple tables}
|
|
\usage{
|
|
REDCap_split(records, metadata)
|
|
}
|
|
\arguments{
|
|
\item{records}{Exported project records. May be a \code{data.frame} or
|
|
\code{character} vector containing JSON from an API call.}
|
|
|
|
\item{metadata}{Project metadata (the data dictionary). May be a
|
|
\code{data.frame} or \code{character} vector containing JSON from an API
|
|
call.}
|
|
}
|
|
\value{
|
|
A list of \code{"data.frame"}s: one base table and zero or more
|
|
tables for each repeating instrument.
|
|
}
|
|
\description{
|
|
This will take output from a REDCap export and split it into a base table
|
|
and child tables for each repeating instrument. Metadata
|
|
is used to determine which fields should be included in each resultant table.
|
|
}
|
|
\examples{
|
|
\dontrun{
|
|
# Using an API call -------------------------------------------------------
|
|
|
|
library(RCurl)
|
|
|
|
# Get the records
|
|
records <- postForm(
|
|
uri = api_url, # Supply your site-specific URI
|
|
token = api_token, # Supply your own API token
|
|
content = 'record',
|
|
format = 'json',
|
|
returnFormat = 'json'
|
|
)
|
|
|
|
# Get the metadata
|
|
metadata <- postForm(
|
|
uri = api_url, # Supply your site-specific URI
|
|
token = api_token, # Supply your own API token
|
|
content = 'metadata',
|
|
format = 'json'
|
|
)
|
|
|
|
# Convert exported JSON strings into a list of data.frames
|
|
REDCapRITS::REDCap_split(records, metadata)
|
|
|
|
# Using a raw data export -------------------------------------------------
|
|
|
|
# Get the records
|
|
records <- read.csv("/path/to/data/ExampleProject_DATA_2018-06-03_1700.csv")
|
|
|
|
# Get the metadata
|
|
metadata <- read.csv("/path/to/data/ExampleProject_DataDictionary_2018-06-03.csv")
|
|
|
|
# Split the tables
|
|
REDCapRITS::REDCap_split(records, metadata)
|
|
|
|
# In conjunction with the R export script ---------------------------------
|
|
|
|
# You must set the working directory first since the REDCap data export script
|
|
# contains relative file references.
|
|
setwd("/path/to/data/")
|
|
|
|
# Run the data export script supplied by REDCap.
|
|
# This will create a data.frame of your records called 'data'
|
|
source("ExampleProject_R_2018-06-03_1700.r")
|
|
|
|
# Get the metadata
|
|
metadata <- read.csv("ExampleProject_DataDictionary_2018-06-03.csv")
|
|
|
|
# Split the tables
|
|
REDCapRITS::REDCap_split(data, metadata)
|
|
}
|
|
}
|
|
\author{
|
|
Paul W. Egeler, M.S., GStat
|
|
}
|