Skip to content

Commit

Permalink
resolve tidyselect warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ezraporter committed Nov 25, 2024
1 parent cd0a181 commit 4fd7e05
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ check_fields_are_checkboxes <- function(metadata_tbl, call = caller_env()) {
check_equal_col_summaries <- function(data, col1, col2, call = caller_env()) {
summary <- data %>%
summarise(
.by = col1,
n = n_distinct(col2)
.by = {{ col1 }},
n = n_distinct({{ col2 }})
)

total_n <- summary %>%
Expand All @@ -767,11 +767,11 @@ check_equal_col_summaries <- function(data, col1, col2, call = caller_env()) {
if (!all(total_n == 1)) {
col1_n_vals <- summary %>%
filter(.data$n > 1) %>%
pull(col1)
pull({{ col1 }})

col2_n_vals <- data %>% # nolint: object_usage_linter
filter(col1 %in% col1_n_vals) %>%
pull(col2)
filter({{ col1 }} %in% col1_n_vals) %>%
pull({{ col2 }})

msg <- c(
x = "{.code {col1_n_vals}} checkbox field{?s} resulted in multiple output columns: {.code {col2_n_vals}}.",
Expand Down
2 changes: 1 addition & 1 deletion R/clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ convert_mixed_instrument <- function(db_data_long, mixed_structure_ref) {
TRUE ~ .data$redcap_repeat_instrument
)
) %>%
select(-.data$update_mask)
select(-"update_mask")
}

db_data_long
Expand Down
18 changes: 9 additions & 9 deletions R/combine_checkboxes.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ combine_checkboxes <- function(supertbl,
data_tbl_mod <- data_tbl_mod %>%
mutate(
across(
selected_cols,
all_of(selected_cols),
~ replace_true(.x,
cur_column(),
metadata = metadata_spec,
raw_or_label = raw_or_label
)
),
across(selected_cols, as.character) # enforce to character strings
across(all_of(selected_cols), as.character) # enforce to character strings
)

new_cols <- metadata_spec %>%
nest(.by = .data$.new_value, .key = "metadata") %>%
nest(.by = ".new_value", .key = "metadata") %>%
pmap(convert_checkbox_vals,
data_tbl = data_tbl_mod,
raw_or_label = raw_or_label, multi_value_label = multi_value_label, values_fill = values_fill
Expand All @@ -156,7 +156,7 @@ combine_checkboxes <- function(supertbl,
# Keep or remove original multi columns
if (!keep) {
final_tbl <- final_tbl %>%
select(-selected_cols)
select(!all_of(selected_cols))
}

# Update the supertbl data tibble
Expand Down Expand Up @@ -191,12 +191,12 @@ get_metadata_spec <- function(metadata_tbl,
if (!is.null(names_glue)) {
# Similar to pivot_*, use of `names_glue` overrides use of names_prefix/sep
glue_env <- out %>%
select(.data$.value)
select(".value")

glue_env$.new_value <- as.character(glue::glue_data(glue_env, names_glue))

glue_env <- glue_env %>%
select(.data$.new_value)
select(".new_value")

out <- cbind(out, glue_env)
} else {
Expand All @@ -210,7 +210,7 @@ get_metadata_spec <- function(metadata_tbl,

# Check that for each unique value of .value there is one unique value of .new_value
# May be removed in the future
check_equal_col_summaries(out, ".value", ".new_value") # nolint: object_usage_linter
check_equal_col_summaries(out, ".value", ".new_value")

# Make sure selection is checkbox metadata field type
check_fields_are_checkboxes(out)
Expand All @@ -226,8 +226,8 @@ get_metadata_spec <- function(metadata_tbl,
}

bind_cols(out, parsed_vals) %>%
select(.data$field_name, .data$raw, .data$label, .data$.value, .data$.new_value) %>%
relocate(c(.data$.value, .data$.new_value), .after = .data$field_name)
select("field_name", "raw", "label", ".value", ".new_value") %>%
relocate(".value", ".new_value", .after = "field_name")
}

#' @title Replace checkbox TRUEs with raw_or_label values
Expand Down
2 changes: 1 addition & 1 deletion R/read_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -571,5 +571,5 @@ get_repeat_event_types <- function(data) {
is_duplicated = (duplicated(.data$redcap_event_name) | duplicated(.data$redcap_event_name, fromLast = TRUE))
) %>%
filter(!.data$is_duplicated | (.data$is_duplicated & .data$repeat_type == "repeat_separate")) %>%
select(-.data$is_duplicated)
select(-"is_duplicated")
}

0 comments on commit 4fd7e05

Please sign in to comment.