mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-21 05:59:07 +02:00
gp with CRAN in sight
This commit is contained in:
parent
20f08c271b
commit
349ff695e1
24 changed files with 338 additions and 157 deletions
|
|
@ -48,15 +48,16 @@
|
|||
#' 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")
|
||||
#' 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.
|
||||
#' # 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.
|
||||
|
|
@ -148,7 +149,8 @@ REDCap_split <- function(records,
|
|||
|
||||
if (forms == "repeating" && primary_table_name %in% subtables) {
|
||||
warning(
|
||||
"The label given to the primary table is already used by a repeating instrument. The primary table label will be left blank."
|
||||
"The label given to the primary table is already used by a repeating
|
||||
instrument. The primary table label will be left blank."
|
||||
)
|
||||
primary_table_name <- ""
|
||||
} else if (primary_table_name > "") {
|
||||
|
|
@ -159,7 +161,8 @@ REDCap_split <- function(records,
|
|||
for (i in names(out)) {
|
||||
if (i == primary_table_name) {
|
||||
out_fields <- which(vars_in_data %in% c(universal_fields,
|
||||
fields[!fields[, 2] %in% subtables, 1]))
|
||||
fields[!fields[, 2] %in%
|
||||
subtables, 1]))
|
||||
out[[primary_table_index]] <-
|
||||
out[[primary_table_index]][out_fields]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#' Download REDCap data
|
||||
#'
|
||||
#' Implementation of REDCap_split with a focused data acquisition approach using
|
||||
#' REDCapR::redcap_read nad only downloading specified fields, forms and/or events
|
||||
#' using the built-in focused_metadata
|
||||
#' including some clean-up. Works with longitudinal projects with repeating
|
||||
#' instruments.
|
||||
#' REDCapR::redcap_read nad only downloading specified fields, forms and/or
|
||||
#' events using the built-in focused_metadata including some clean-up.
|
||||
#' Works with longitudinal projects with repeating instruments.
|
||||
#' @param uri REDCap database uri
|
||||
#' @param token API token
|
||||
#' @param records records to download
|
||||
|
|
@ -12,7 +11,8 @@
|
|||
#' @param events events to download
|
||||
#' @param forms forms to download
|
||||
#' @param raw_or_label raw or label tags
|
||||
#' @param split_forms Whether to split "repeating" or "all" forms, default is all.
|
||||
#' @param split_forms Whether to split "repeating" or "all" forms, default is
|
||||
#' all.
|
||||
#' @param generics vector of auto-generated generic variable names to
|
||||
#' ignore when discarding empty rows
|
||||
#'
|
||||
|
|
@ -73,7 +73,8 @@ read_redcap_tables <- function(uri,
|
|||
)[["data"]]
|
||||
|
||||
# Process repeat instrument naming
|
||||
# Removes any extra characters other than a-z, 0-9 and "_", to mimic raw instrument names.
|
||||
# Removes any extra characters other than a-z, 0-9 and "_", to mimic raw
|
||||
# instrument names.
|
||||
if ("redcap_repeat_instrument" %in% names(d)) {
|
||||
d$redcap_repeat_instrument <-
|
||||
gsub("[^a-z0-9_]", "", gsub(" ", "_", tolower(d$redcap_repeat_instrument)))
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ redcap_wider <-
|
|||
inst.glue = "{.value}_{redcap_repeat_instance}") {
|
||||
all_names <- unique(do.call(c, lapply(list, names)))
|
||||
|
||||
if (!any(c("redcap_event_name", "redcap_repeat_instrument") %in% all_names)) {
|
||||
if (!any(c("redcap_event_name", "redcap_repeat_instrument") %in%
|
||||
all_names)) {
|
||||
stop(
|
||||
"The dataset does not include a 'redcap_event_name' variable.
|
||||
redcap_wider only handles projects with repeating instruments or
|
||||
|
|
@ -35,11 +36,6 @@ redcap_wider <-
|
|||
)
|
||||
}
|
||||
|
||||
# if (any(grepl("_timestamp",all_names))){
|
||||
# stop("The dataset includes a '_timestamp' variable, which is not supported
|
||||
# by this function yet. Sorry! Feel free to contribute :)")
|
||||
# }
|
||||
|
||||
id.name <- all_names[1]
|
||||
|
||||
l <- lapply(list, function(i) {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,8 @@ match_fields_to_form <- function(metadata, vars_in_data) {
|
|||
names(fields) <- c("field_name", "form_name")
|
||||
|
||||
# Process instrument status fields
|
||||
form_names <- unique(metadata[,grepl(".*[Ff]orm[._][Nn]ame$",names(metadata))])
|
||||
form_names <- unique(metadata[,grepl(".*[Ff]orm[._][Nn]ame$",
|
||||
names(metadata))])
|
||||
form_complete_fields <- data.frame(
|
||||
field_name = paste0(form_names, "_complete"),
|
||||
form_name = form_names,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue