diff --git a/R/R/REDCap_split.r b/R/R/REDCap_split.r index 34feca1..485e48f 100644 --- a/R/R/REDCap_split.r +++ b/R/R/REDCap_split.r @@ -40,6 +40,7 @@ #' @export REDCap_split <- function(records, metadata) { + # Process user input records <- JSON2data.frame(records) metadata <- JSON2data.frame(metadata) @@ -52,6 +53,24 @@ REDCap_split <- function(records, metadata) { } + # Standardize variable names for metadata + names(metadata) <- c( + "field_name", "form_name", "section_header", "field_type", + "field_label", "select_choices_or_calculations", "field_note", + "text_validation_type_or_show_slider_number", "text_validation_min", + "text_validation_max", "identifier", "branching_logic", "required_field", + "custom_alignment", "question_number", "matrix_group_name", "matrix_ranking", + "field_annotation" + ) + + # Make sure that no metadata columns are factors + metadata_factors <- sapply(metadata, inherits, "factor") + if(any(metadata_factors)) { + + metadata[metadata_factors] <- lapply(metadata[metadata_factors], as.character) + + } + # Find the fields and associated form fields <- metadata[ !metadata$field_type %in% c("descriptive", "checkbox"),