2018-06-03 22:08:26 +02:00
|
|
|
% 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{
|
2018-06-23 04:24:34 +02:00
|
|
|
\item{records}{Exported project records. May be a \code{data.frame},
|
|
|
|
\code{response}, or \code{character} vector containing JSON from an API
|
|
|
|
call.}
|
2018-06-03 22:08:26 +02:00
|
|
|
|
|
|
|
\item{metadata}{Project metadata (the data dictionary). May be a
|
2018-06-23 04:24:34 +02:00
|
|
|
\code{data.frame}, \code{response}, or \code{character} vector containing
|
|
|
|
JSON from an API call.}
|
2018-06-03 22:08:26 +02:00
|
|
|
}
|
|
|
|
\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{
|
2018-06-09 05:47:34 +02:00
|
|
|
# Using an API call -------------------------------------------------------
|
|
|
|
|
2018-06-03 22:08:26 +02:00
|
|
|
library(RCurl)
|
|
|
|
|
|
|
|
# Get the records
|
2018-06-03 22:46:25 +02:00
|
|
|
records <- postForm(
|
2018-06-09 05:47:34 +02:00
|
|
|
uri = api_url, # Supply your site-specific URI
|
|
|
|
token = api_token, # Supply your own API token
|
|
|
|
content = 'record',
|
|
|
|
format = 'json',
|
|
|
|
returnFormat = 'json'
|
2018-06-03 22:08:26 +02:00
|
|
|
)
|
|
|
|
|
2018-06-03 22:46:25 +02:00
|
|
|
# Get the metadata
|
|
|
|
metadata <- postForm(
|
2018-06-09 05:47:34 +02:00
|
|
|
uri = api_url, # Supply your site-specific URI
|
|
|
|
token = api_token, # Supply your own API token
|
|
|
|
content = 'metadata',
|
|
|
|
format = 'json'
|
2018-06-03 22:46:25 +02:00
|
|
|
)
|
|
|
|
|
2018-06-03 22:08:26 +02:00
|
|
|
# Convert exported JSON strings into a list of data.frames
|
2018-06-09 05:47:34 +02:00
|
|
|
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)
|
2018-06-03 22:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
\author{
|
|
|
|
Paul W. Egeler, M.S., GStat
|
|
|
|
}
|