From 57a0538a11c20606bf4a74c02b4fe9e6de47c3c5 Mon Sep 17 00:00:00 2001 From: "Egeler, Paul W" Date: Mon, 4 Jun 2018 17:19:37 -0400 Subject: [PATCH] bypassing factor field capture routine when no factor fields present --- R/R/REDCap_split.r | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/R/R/REDCap_split.r b/R/R/REDCap_split.r index 9f411fb..83d4faf 100644 --- a/R/R/REDCap_split.r +++ b/R/R/REDCap_split.r @@ -112,27 +112,30 @@ REDCap_split <- function(records, metadata) { fields <- rbind(fields, form_complete_fields) # Process ".*\\.factor" fields supplied by REDCap's export data R script - factor_fields <- - do.call( - "rbind", - apply( - fields, - 1, - function(x, y) { - field_indices <- grepl(paste0("^", x[1], "\\.factor$"), y) - if (any(field_indices)) - data.frame( - field_name = y[field_indices], - form_name = x[2], - stringsAsFactors = FALSE, - row.names = NULL - ) - }, - y = names(records) - ) - ) + if (any(grepl("\\.factor$", names(records)))) { - fields <- rbind(fields, factor_fields) + factor_fields <- + do.call( + "rbind", + apply( + fields, + 1, + function(x, y) { + field_indices <- grepl(paste0("^", x[1], "\\.factor$"), y) + if (any(field_indices)) + data.frame( + field_name = y[field_indices], + form_name = x[2], + stringsAsFactors = FALSE, + row.names = NULL + ) + }, + y = names(records) + ) + ) + + fields <- rbind(fields, factor_fields) + } # Identify the subtables in the data subtables <- unique(records$redcap_repeat_instrument)