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{
|
2022-12-21 07:43:56 +01:00
|
|
|
REDCap_split(
|
|
|
|
records,
|
|
|
|
metadata,
|
|
|
|
primary_table_name = "",
|
|
|
|
forms = c("repeating", "all")
|
|
|
|
)
|
2018-06-03 22:08:26 +02:00
|
|
|
}
|
|
|
|
\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.}
|
2019-07-01 22:54:29 +02:00
|
|
|
|
2019-07-08 18:19:33 +02:00
|
|
|
\item{primary_table_name}{Name given to the list element for the primary
|
|
|
|
output table (as described in \emph{README.md}). Ignored if
|
|
|
|
\code{forms = 'all'}.}
|
|
|
|
|
|
|
|
\item{forms}{Indicate whether to create separate tables for repeating
|
|
|
|
instruments only or for all forms.}
|
2018-06-03 22:08:26 +02:00
|
|
|
}
|
|
|
|
\value{
|
2019-07-08 18:19:33 +02:00
|
|
|
A list of \code{"data.frame"}s. The number of tables will differ
|
|
|
|
depending on the \code{forms} option selected.
|
|
|
|
\itemize{
|
|
|
|
\item \code{'repeating'}: one base table and one or more
|
|
|
|
tables for each repeating instrument.
|
|
|
|
\item \code{'all'}: a data.frame for each instrument, regardless of
|
|
|
|
whether it is a repeating instrument or not.
|
|
|
|
}
|
2018-06-03 22:08:26 +02:00
|
|
|
}
|
|
|
|
\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
|
2023-04-13 10:57:04 +02:00
|
|
|
metadata <- read.csv(
|
|
|
|
"/path/to/data/ExampleProject_DataDictionary_2018-06-03.csv")
|
2018-06-09 05:47:34 +02:00
|
|
|
|
|
|
|
# Split the tables
|
|
|
|
REDCapRITS::REDCap_split(records, metadata)
|
|
|
|
|
|
|
|
# In conjunction with the R export script ---------------------------------
|
|
|
|
|
2023-04-13 10:57:04 +02:00
|
|
|
# You must set the working directory first since the REDCap data export
|
|
|
|
# script contains relative file references.
|
2018-06-09 05:47:34 +02:00
|
|
|
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
|
|
|
|
}
|