From e1ae1d001a20b34167f9f6731d89511c1ad93ead Mon Sep 17 00:00:00 2001 From: pegeler Date: Fri, 8 Jun 2018 23:24:35 -0400 Subject: [PATCH] r-pkg: adding more examples. Will make some of them live with exdata in the future. --- R/R/REDCap_split.r | 49 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/R/R/REDCap_split.r b/R/R/REDCap_split.r index da6cba9..f1ac040 100644 --- a/R/R/REDCap_split.r +++ b/R/R/REDCap_split.r @@ -12,27 +12,56 @@ #' @author Paul W. Egeler, M.S., GStat #' @examples #' \dontrun{ +#' # 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' +#' 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, -#' token = api_token, -#' content = 'metadata', -#' format = 'json' +#' 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 -#' REDCap_split(records, metadata) +#' 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) #' } #' @return A list of \code{"data.frame"}s: one base table and zero or more #' tables for each repeating instrument.