REDCapCAST/R/man/REDCap_split.Rd

84 lines
2.4 KiB
Plaintext
Raw Normal View History

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{
\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
\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
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
)
# 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: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
}