if (FALSE) {
# 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
REDCapCAST::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
REDCapCAST::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.
old <- getwd()
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 metadatan
metadata <- read.csv("ExampleProject_DataDictionary_2018-06-03.csv")
# Split the tables
REDCapCAST::REDCap_split(data, metadata)
setwd(old)
}
Run the code above in your browser using DataLab