Skip to content

Commit

Permalink
qualify with .data
Browse files Browse the repository at this point in the history
to avoid R CMD check warnings

ref #420
  • Loading branch information
wibeasley committed Oct 2, 2022
1 parent db7a393 commit 0075c26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/redcap-metadata-coltypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ redcap_metadata_internal <- function(
field_order_within_form = seq_len(dplyr::n()),
) %>%
dplyr::ungroup() %>%
dplyr::arrange(form_order, field_order_within_form) %>%
dplyr::select(-form_order, -field_order_within_form) %>%
dplyr::arrange(.data$form_order, .data$field_order_within_form) %>%
dplyr::select(-.data$form_order, -.data$field_order_within_form) %>%
tibble::add_row(d_again, .after = 1)

# setdiff(d_meta$field_name_base, d_var$original_field_name)
Expand Down
20 changes: 12 additions & 8 deletions playgrounds/eav-playground-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ requireNamespace("testit")
# ---- declare-globals ---------------------------------------------------------
redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
token <- "9A81268476645C4E5F03428B8AC3AA7B" # PHI-free demo: simple static
# token <- "5007DC786DBE39CE77ED8DD0C68069A6" # PHI-free demo: Checkboxes 1
# token <- "CCB7E11837D41126D67C744F97389E04" # PHI-free demo: super-wide --3,000 columns
token <- "5007DC786DBE39CE77ED8DD0C68069A6" # PHI-free demo: Checkboxes 1
token <- "CCB7E11837D41126D67C744F97389E04" # PHI-free demo: super-wide --3,000 columns
# token <- "5C1526186C4D04AE0A0630743E69B53C" # PHI-free demo: super-wide #3--35,000 columns
# token <- "56F43A10D01D6578A46393394D76D88F" # PHI-free demo: Repeating Instruments --Sparse
token <- "56F43A10D01D6578A46393394D76D88F" # PHI-free demo: Repeating Instruments --Sparse

# fields <- c("record_id", "dob")
# forms <- "health"
Expand All @@ -29,7 +29,7 @@ system.time(
system.time({
col_types <- REDCapR::redcap_metadata_coltypes(redcap_uri, token, print_col_types_to_console = FALSE)

View(REDCapR::redcap_variables(redcap_uri, token)$data)
# View(REDCapR::redcap_variables(redcap_uri, token)$data)

ds_metadata <-
REDCapR:::redcap_metadata_internal(redcap_uri, token)$d_variable %>%
Expand All @@ -42,7 +42,7 @@ system.time({
ds_eav <- REDCapR:::redcap_read_eav_oneshot(redcap_uri, token, fields = desired_fields)$data
})

testit::assert(sort(ds_metadata$field_name) == sort(colnames(ds_expected)))
testit::assert(ds_metadata$field_name == colnames(ds_expected))
testthat::expect_setequal( ds_metadata$field_name, colnames(ds_expected))

# ---- tweak-data --------------------------------------------------------------
Expand Down Expand Up @@ -75,15 +75,19 @@ ds_eav_2 <-
ds <-
ds_eav_2 %>%
dplyr::select(-.data$field_type, -.data$field_name_base) %>%
# dplyr::group_by(record, redcap_repeat_instrument, redcap_repeat_instance, event_id, field_name) %>%
# dplyr::summarise(n = dplyr::n(), .groups = "drop") %>%
# dplyr::filter(n > 1L) %>%
# View()
# dplyr::select(-.data$redcap_repeat_instance) %>% # TODO: need a good fix for repeats
# tidyr::drop_na(event_id) %>% # TODO: need a good fix for repeats
tidyr::pivot_wider( # Everything else is considered an ID column
names_from = field_name,
values_from = value
names_from = .data$field_name,
values_from = .data$value
) %>%
dplyr::select(!!ds_metadata$field_name) %>%
readr::type_convert(col_types)
# dplyr::select(.data = ., !!intersect(variables_to_keep, colnames(.)))

testit::assert(sort(colnames(ds)) == sort(colnames(ds_expected)))
testit::assert(colnames(ds) == colnames(ds_expected))
testthat::expect_setequal(colnames(ds), colnames(ds_expected))

0 comments on commit 0075c26

Please sign in to comment.