Skip to content

Commit

Permalink
Reinstate single instance for nonrepeat
Browse files Browse the repository at this point in the history
  • Loading branch information
rsh52 committed Sep 23, 2024
1 parent 37b88a8 commit 7f64232
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions R/clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/read_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/add_event_mapping.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7f64232

Please sign in to comment.