REDCapCAST/man/REDCap_split.Rd

106 lines
3.0 KiB
Plaintext
Raw Permalink 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{
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{
\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.}
\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{
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
records <- postForm(
2024-02-27 13:20:21 +01:00
uri = api_url, # Supply your site-specific URI
2018-06-09 05:47:34 +02:00
token = api_token, # Supply your own API token
2024-02-27 13:20:21 +01:00
content = "record",
format = "json",
returnFormat = "json"
2018-06-03 22:08:26 +02:00
)
# Get the metadata
metadata <- postForm(
2024-02-27 13:20:21 +01:00
uri = api_url, # Supply your site-specific URI
2018-06-09 05:47:34 +02:00
token = api_token, # Supply your own API token
2024-02-27 13:20:21 +01:00
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
2023-04-13 10:57:04 +02:00
metadata <- read.csv(
2024-02-27 13:20:21 +01:00
"/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.
2023-06-05 08:43:03 +02:00
old <- getwd()
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")
2023-06-05 08:43:03 +02:00
# Get the metadatan
2018-06-09 05:47:34 +02:00
metadata <- read.csv("ExampleProject_DataDictionary_2018-06-03.csv")
# Split the tables
REDCapRITS::REDCap_split(data, metadata)
2023-06-05 08:43:03 +02:00
setwd(old)
2018-06-03 22:08:26 +02:00
}
}
\author{
Paul W. Egeler, M.S., GStat
}