diff --git a/R/clean_redcap_long.R b/R/clean_redcap_long.R index 750578cc..13171692 100644 --- a/R/clean_redcap_long.R +++ b/R/clean_redcap_long.R @@ -450,6 +450,9 @@ convert_mixed_instrument <- function(db_data_long, mixed_structure_ref) { db_data_long <- db_data_long %>% mutate( redcap_repeat_instance = case_when( + # Add single instance repeat event instance vals when none exist + # This handles nonrepeating data in events set to repeat separately + update_mask & is.na(redcap_repeat_instance) ~ 1, # If repeat-together type, remove values from redcap_repeat_instance # (shifted and captured in redcap_event_instance) update_mask & is.na(redcap_repeat_instrument) ~ NA, diff --git a/R/read_redcap.R b/R/read_redcap.R index 4cb6751f..0e5e8e6f 100644 --- a/R/read_redcap.R +++ b/R/read_redcap.R @@ -443,7 +443,7 @@ add_metadata <- function(supertbl, db_metadata, redcap_uri, token, suppress_redc #' @param supertbl a supertibble object to supplement with metadata #' @param linked_arms the tibble with event mappings created by #' \code{link_arms()} -#' @param repeat_event_types a dataframe output from [repeat_event_types()] which +#' @param repeat_event_types a dataframe output from [get_repeat_event_types()] which #' specifies NR, RS, and RT types for events #' #' @return diff --git a/man/add_event_mapping.Rd b/man/add_event_mapping.Rd index 3fe9a8a3..5c6d68df 100644 --- a/man/add_event_mapping.Rd +++ b/man/add_event_mapping.Rd @@ -13,7 +13,7 @@ add_event_mapping(supertbl, linked_arms, repeat_event_types) \item{linked_arms}{the tibble with event mappings created by \code{link_arms()}} -\item{repeat_event_types}{a dataframe output from \code{\link[=repeat_event_types]{repeat_event_types()}} which +\item{repeat_event_types}{a dataframe output from \code{\link[=get_repeat_event_types]{get_repeat_event_types()}} which specifies NR, RS, and RT types for events} } \value{ diff --git a/tests/testthat/test-clean_redcap_long.R b/tests/testthat/test-clean_redcap_long.R index 3cf78be7..3a68e780 100644 --- a/tests/testthat/test-clean_redcap_long.R +++ b/tests/testthat/test-clean_redcap_long.R @@ -112,7 +112,7 @@ test_that("clean_redcap_long with mixed structure works", { # Check redcap_data contents for mixed and nonrepeating structure expected_mixed_data <- tibble::tribble( ~record_id, ~redcap_event, ~redcap_form_instance, ~mixed_structure_1, ~form_status_complete, - 1, "event_1", NA, "Mixed Nonrepeat 1", 0, + 1, "event_1", 1, "Mixed Nonrepeat 1", 0, 1, "event_2", 1, "Mixed Repeat 1", 0, 1, "event_2", 2, "Mixed Repeat 2", 0 ) @@ -309,7 +309,7 @@ test_that("convert_mixed_instrument works", { expected_out <- tibble::tribble( ~record_id, ~redcap_repeat_instrument, ~redcap_repeat_instance, ~mixed_structure_variable, ~repeat_form_variable, ~mixed_repeat_var, - 1, "mixed_structure_form", NA, "A", NA, NA, + 1, "mixed_structure_form", 1, "A", NA, NA, 2, "mixed_structure_form", 1, "B", NA, NA, 3, "repeat_form", 1, NA, "C", NA, 4, "repeat_form", 2, NA, "D", NA,