Skip to content

Commit

Permalink
Update link_arms, add event names column to redcap_events output
Browse files Browse the repository at this point in the history
  • Loading branch information
rsh52 committed Sep 11, 2024
1 parent 595abda commit 436fbc6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/REDCapTidieR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/read_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", "redcap_arm", "arm_name", "event_name"
) %>%
nest(redcap_events = !"redcap_form_name")

Expand Down
14 changes: 13 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 436fbc6

Please sign in to comment.