Updated read_redcap_tables to handle non-longitudinal projects and give better error on invalid events or forms

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-01-09 10:22:49 +01:00
parent b5c0a1af34
commit 7cae55dba4
4 changed files with 27 additions and 15 deletions

View File

@ -2,9 +2,10 @@ Package: REDCapCAST
Title: REDCap Castellated Data Handling
Version: 23.12.1
Authors@R: c(
person("Andreas Gammelgaard", "Damsbo", email = "agdamsbo@clin.au.dk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7559-1154")),
person("Paul", "Egeler", email = "paul.egeler@spectrumhealth.org", role = "aut"))
person("Andreas Gammelgaard", "Damsbo", email = "agdamsbo@clin.au.dk",
role = c("aut", "cre"),comment = c(ORCID = "0000-0002-7559-1154")),
person("Paul", "Egeler", email = "paulegeler@gmail.com", role = c("aut"),
comment = c(ORCID = "0000-0001-6948-9498")))
Description: Originally forked from the R part of 'REDCapRITS' by Paul Egeler.
See <https://github.com/pegeler/REDCapRITS>.
Handles castellated datasets from 'REDCap' projects with repeating instruments.

View File

@ -1,3 +1,9 @@
# REDCapCAST 24.1.1
### 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.
# REDCapCAST 23.12.1
One new function to ease secure dataset retrieval and a few bug fixes.

View File

@ -1,9 +1,10 @@
#' Download REDCap data
#'
#' Implementation of REDCap_split with a focused data acquisition approach using
#' REDCapR::redcap_read nad only downloading specified fields, forms and/or
#' REDCapR::redcap_read and only downloading specified fields, forms and/or
#' events using the built-in focused_metadata including some clean-up.
#' Works with longitudinal projects with repeating instruments.
#' Works with classical and longitudinal projects with or without repeating
#' instruments.
#' @param uri REDCap database uri
#' @param token API token
#' @param records records to download
@ -39,27 +40,30 @@ read_redcap_tables <- function(uri,
)) {
if (!is.null(forms) | !is.null(events)){
arm_event_inst <- REDCapR::redcap_event_instruments(redcap_uri = uri,
token = token)
m <- REDCapR::redcap_metadata_read(redcap_uri = uri, token = token)[["data"]]
if (!is.null(forms)){
forms_test <- forms %in% unique(arm_event_inst$data$form)
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=", "),"."))
stop("Not all supplied forms are valid")
}
}
if (!is.null(events)){
arm_event_inst <- REDCapR::redcap_event_instruments(redcap_uri = uri,
token = token)
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=", "),"."))
stop("Not all supplied event names are valid")
}
}
}
# Getting dataset
d <- REDCapR::redcap_read(

View File

@ -43,9 +43,10 @@ list of instruments
}
\description{
Implementation of REDCap_split with a focused data acquisition approach using
REDCapR::redcap_read nad only downloading specified fields, forms and/or
REDCapR::redcap_read and only downloading specified fields, forms and/or
events using the built-in focused_metadata including some clean-up.
Works with longitudinal projects with repeating instruments.
Works with classical and longitudinal projects with or without repeating
instruments.
}
\examples{
# Examples will be provided later