field names validity checking also added while at it

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-01-09 10:27:37 +01:00
parent 7cae55dba4
commit 407ff1e73a
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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")
}
}