diff --git a/NEWS.md b/NEWS.md index 6172559..3b0fd1a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ ### Functions -* Fix: `read_redcap_tables()`: checking form names based on data dictionary to allow handling of non-longitudinal projects. Prints invalid form names and invalid event names. If invalid form names are supplied to `REDCapR::redcap_read()` (which is the backbone), all forms are exported, which is not what we want with a focused approach. Invalid event names will give an output with a rather peculiar formatting. +* Fix: `read_redcap_tables()`: checking form names based on data dictionary to allow handling of non-longitudinal projects. Prints invalid form names and invalid event names. If invalid form names are supplied to `REDCapR::redcap_read()` (which is the backbone), all forms are exported, which is not what we want with a focused approach. Invalid event names will give an output with a rather peculiar formatting. Checking of field names validity is also added. # REDCapCAST 23.12.1 diff --git a/R/read_redcap_tables.R b/R/read_redcap_tables.R index 4913c12..7a4ae26 100644 --- a/R/read_redcap_tables.R +++ b/R/read_redcap_tables.R @@ -42,6 +42,16 @@ read_redcap_tables <- function(uri, m <- REDCapR::redcap_metadata_read(redcap_uri = uri, token = token)[["data"]] + if (!is.null(fields)){ + + fields_test <- fields %in% unique(m$field_name) + + if (any(!fields_test)){ + print(paste0("The following field names are invalid: ", paste(fields[!fields_test],collapse=", "),".")) + stop("Not all supplied field names are valid") + } + } + if (!is.null(forms)){ @@ -49,7 +59,7 @@ read_redcap_tables <- function(uri, if (any(!forms_test)){ print(paste0("The following form names are invalid: ", paste(forms[!forms_test],collapse=", "),".")) - stop("Not all supplied forms are valid") + stop("Not all supplied form names are valid") } }