allows not splitting data

This commit is contained in:
Andreas Gammelgaard Damsbo 2025-03-05 13:40:56 +01:00
parent 2e1e7822a4
commit 0b5319f647
No known key found for this signature in database

View File

@ -26,7 +26,7 @@
#' \link[REDCapCAST]{fct_drop} to drop empty levels.
#'
#' @param split_forms Whether to split "repeating" or "all" forms, default is
#' all.
#' all. Give "none" to export native semi-long REDCap format
#' @param ... passed on to \link[REDCapR]{redcap_read}
#'
#' @return list of instruments
@ -43,10 +43,10 @@ read_redcap_tables <- function(uri,
events = NULL,
forms = NULL,
raw_or_label = c("raw", "label", "both"),
split_forms = "all",
split_forms = c("all", "repeating", "none"),
...) {
raw_or_label <- match.arg(raw_or_label, c("raw", "label", "both"))
split_forms <- match.arg(split_forms)
# Getting metadata
m <-
@ -56,8 +56,10 @@ read_redcap_tables <- function(uri,
fields_test <- fields %in% c(m$field_name, paste0(unique(m$form_name), "_complete"))
if (any(!fields_test)) {
print(paste0("The following field names are invalid: ",
paste(fields[!fields_test], collapse = ", "), "."))
print(paste0(
"The following field names are invalid: ",
paste(fields[!fields_test], collapse = ", "), "."
))
stop("Not all supplied field names are valid")
}
}
@ -67,8 +69,10 @@ read_redcap_tables <- function(uri,
forms_test <- forms %in% unique(m$form_name)
if (any(!forms_test)) {
print(paste0("The following form names are invalid: ",
paste(forms[!forms_test], collapse = ", "), "."))
print(paste0(
"The following form names are invalid: ",
paste(forms[!forms_test], collapse = ", "), "."
))
stop("Not all supplied form names are valid")
}
}
@ -82,8 +86,10 @@ read_redcap_tables <- function(uri,
event_test <- events %in% unique(arm_event_inst$data$unique_event_name)
if (any(!event_test)) {
print(paste0("The following event names are invalid: ",
paste(events[!event_test], collapse = ", "), "."))
print(paste0(
"The following event names are invalid: ",
paste(events[!event_test], collapse = ", "), "."
))
stop("Not all supplied event names are valid")
}
}
@ -123,15 +129,16 @@ read_redcap_tables <- function(uri,
# Processing metadata to reflect focused dataset
m <- focused_metadata(m, names(d))
# Splitting
out <- REDCap_split(d,
if (split_forms != "none") {
REDCap_split(d,
m,
forms = split_forms,
primary_table_name = ""
)
sanitize_split(out)
) |> sanitize_split()
} else {
d
}
}
@ -234,5 +241,3 @@ apply_factor_labels <- function(data,meta=NULL){
}
}) |> dplyr::bind_cols()
}