diff --git a/NAMESPACE b/NAMESPACE index 64b1519b..b74e60ed 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(read_redcap) export(write_redcap_xlsx) importFrom(REDCapR,redcap_arm_export) importFrom(REDCapR,redcap_event_instruments) +importFrom(REDCapR,redcap_event_read) importFrom(REDCapR,redcap_instruments) importFrom(REDCapR,redcap_metadata_read) importFrom(REDCapR,redcap_read_oneshot) diff --git a/NEWS.md b/NEWS.md index 96ede72c..14c724ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ - Added `combine_checkboxes()` analytics function - Use `combine_checkboxes()` to consolidate multiple checkbox fields in a REDCap data tibble under a single column - Fixed a bug for mixed structure databases resulting in data loss when some fields had dual repeating-separately/repeating-together behavior +- Various improvements and additions with CRAN release of REDCapR 1.2.0: + - `event_name` added as a column to the `redcap_event` column of longitudinal supertibbles + - `guess_max` parameter in `read_redcap()` default updated to `Inf` # REDCapTidieR 1.1.1 diff --git a/R/REDCapTidieR-package.R b/R/REDCapTidieR-package.R index 978e6ee3..5771fc22 100644 --- a/R/REDCapTidieR-package.R +++ b/R/REDCapTidieR-package.R @@ -14,7 +14,7 @@ #' @importFrom purrr compose map map2 map_int map_lgl pluck pmap_chr some pmap #' discard flatten_chr map2_chr reduce #' @importFrom REDCapR redcap_arm_export redcap_event_instruments redcap_instruments -#' redcap_metadata_read redcap_read_oneshot sanitize_token +#' redcap_metadata_read redcap_read_oneshot sanitize_token redcap_event_read #' @importFrom rlang .data !!! abort as_closure caller_arg caller_env catch_cnd #' check_installed cnd_muffle current_call current_env enexpr enquo env_poke #' eval_tidy get_env global_env is_atomic is_bare_formula is_bare_list quo_name diff --git a/R/read_redcap.R b/R/read_redcap.R index a350cd3c..874540ce 100644 --- a/R/read_redcap.R +++ b/R/read_redcap.R @@ -451,7 +451,7 @@ add_event_mapping <- function(supertbl, linked_arms) { event_info <- linked_arms %>% add_partial_keys(.data$unique_event_name) %>% select( - redcap_form_name = "form", "redcap_event", "redcap_arm", "arm_name" + redcap_form_name = "form", "redcap_event", "event_name", "redcap_arm", "arm_name" ) %>% nest(redcap_events = !"redcap_form_name") diff --git a/R/utils.R b/R/utils.R index 32dc3a78..44045c6d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -142,7 +142,19 @@ link_arms <- function(redcap_uri, call = caller_env() ) - left_join(db_event_instruments, arms, by = "arm_num") + db_event_labels <- try_redcapr( + { + redcap_event_read( + redcap_uri = redcap_uri, + token = token, + verbose = !suppress_redcapr_messages + ) + }, + call = caller_env() + ) + + left_join(db_event_instruments, arms, by = "arm_num") %>% + left_join(db_event_labels, by = c("arm_num", "unique_event_name")) } #' @title diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 2fe31dbd..299be04e 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -219,7 +219,8 @@ test_that("link_arms works", { expect_s3_class(out, "tbl") # output contains expected columns - expected_cols <- c("arm_num", "unique_event_name", "form", "arm_name") + expected_cols <- c("arm_num", "unique_event_name", "form", "arm_name", + "event_name", "custom_event_label", "event_id") expect_setequal(expected_cols, names(out)) # all arms are represented in output (test redcap has 2 arms)