Skip to content

Commit

Permalink
Styler and lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Hanna authored and Richard Hanna committed Mar 6, 2024
1 parent bd1367e commit e476936
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
11 changes: 5 additions & 6 deletions R/clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ clean_redcap_long <- function(db_data_long,
mixed_structure_ref <- get_mixed_structure_fields(db_data_long) %>%
filter(.data$rep_and_nonrep & !str_ends(.data$field_name, "_form_complete")) %>%
left_join(db_metadata_long %>% select(.data$field_name, .data$form_name),
by = "field_name"
by = "field_name"
)

# Update if project actually has mixed structure
Expand All @@ -96,7 +96,6 @@ clean_redcap_long <- function(db_data_long,
if (has_mixed_structure_forms) {
db_data_long <- convert_mixed_instrument(db_data_long, mixed_structure_ref)
}

} else {
# Throw error if mixed structure detected and not allowed
check_repeat_and_nonrepeat(db_data_long)
Expand All @@ -113,8 +112,10 @@ clean_redcap_long <- function(db_data_long,
linked_arms
)
),
structure = case_when(has_mixed_structure_forms & redcap_form_name %in% mixed_structure_ref$form_name ~ "mixed",
TRUE ~ "repeating")
structure = case_when(
has_mixed_structure_forms & redcap_form_name %in% mixed_structure_ref$form_name ~ "mixed",
TRUE ~ "repeating"
)
)
}

Expand Down Expand Up @@ -274,7 +275,6 @@ distill_repeat_table_long <- function(form_name,
db_data_long,
db_metadata_long,
linked_arms) {

has_repeat_forms <- "redcap_repeat_instance" %in% names(db_data_long)

my_record_id <- names(db_data_long)[1]
Expand Down Expand Up @@ -391,7 +391,6 @@ distill_repeat_table_long <- function(form_name,
#' @keywords internal

convert_mixed_instrument <- function(db_data_long, mixed_structure_ref) {

for (i in seq_len(nrow(mixed_structure_ref))) {
field <- mixed_structure_ref$field_name[i]
form <- mixed_structure_ref$form_name[i]
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ test_that("clean_redcap_long with mixed structure works", {
1, "event_2", "Nonrepeat 2", 0
)

expect_equal(out$redcap_data[out$redcap_form_name == "mixed_structure_form"][[1]],
expected_mixed_data)
expect_equal(
out$redcap_data[out$redcap_form_name == "mixed_structure_form"][[1]],
expected_mixed_data
)

expect_equal(out$redcap_data[out$redcap_form_name == "nonrepeat_form"][[1]],
expected_nonrepeat_data)
expect_equal(
out$redcap_data[out$redcap_form_name == "nonrepeat_form"][[1]],
expected_nonrepeat_data
)
})

test_that("distill_nonrepeat_table_long tibble contains expected columns for longitudinal REDCap databases with arms", {
Expand Down
5 changes: 3 additions & 2 deletions vignettes/articles/diving_deeper.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ Users are cautioned when enabling this feature, since it changes definitions in

```{r}
read_redcap(redcap_uri,
mixed_token,
allow_mixed_structure = TRUE) |>
mixed_token,
allow_mixed_structure = TRUE
) |>
rmarkdown::paged_table()
```

Expand Down

0 comments on commit e476936

Please sign in to comment.