Skip to content

Commit

Permalink
trying to prep for NA check values
Browse files Browse the repository at this point in the history
ref #420
  • Loading branch information
wibeasley committed Oct 2, 2022
1 parent b1dc1d5 commit e0d238d
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions playgrounds/eav-playground-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ 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 <- "5007DC786DBE39CE77ED8DD0C68069A6" # PHI-free demo: Checkboxes 1 #3074
# 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 #2603

# fields <- c("record_id", "dob")
# forms <- "health"
fields <- NULL
forms <- NULL
records <- NULL #c("1")
# blank_for_gray_form_status <- FALSE

# .default_check_for_untouched_forms <- dplyr::if_else(blank_for_gray_form_status, FALSE, NA)

# ---- load-data ---------------------------------------------------------------
# View(REDCapR::redcap_variables(redcap_uri, token)$data)
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)

meta <- REDCapR:::redcap_metadata_internal(redcap_uri, token)
meta <- REDCapR:::redcap_metadata_internal(redcap_uri, token)

ds_metadata <-
meta$d_variable %>%
Expand Down Expand Up @@ -69,6 +70,16 @@ ds_eav_possible <-
tidyr::crossing(field_name = .fields_to_cross)
)

# To try to have checkboxes NA if the forms weren't touched.
# ds_form_pt <-
# ds_metadata %>%
# dplyr::filter(.data$field_type == "complete") %>%
# dplyr::select(.data$field_name, .data$form_name) %>%
# dplyr::inner_join(ds_eav, by = "field_name") %>%
# dplyr::mutate(
# .default_check = dplyr::i
# )

ds_eav_2 <-
ds_eav %>%
dplyr::rename(field_name_base = field_name) %>%
Expand All @@ -77,10 +88,10 @@ ds_eav_2 <-
dplyr::distinct(.data$field_name_base, .data$field_type),
by = "field_name_base"
) %>%
# View()
dplyr::mutate(
field_name = dplyr::if_else(!is.na(.data$field_type) & (.data$field_type == "checkbox"), paste0(.data$field_name_base , "___", .data$value), .data$field_name_base ),
value = dplyr::if_else(!is.na(.data$field_type) & (.data$field_type == "checkbox"), as.character(!is.na(.data$value)), .data$value),
checkbox = !is.na(.data$field_type) & (.data$field_type == "checkbox"),
field_name = dplyr::if_else(.data$checkbox, paste0(.data$field_name_base , "___", .data$value), .data$field_name_base),
value = dplyr::if_else(.data$checkbox, as.character(!is.na(.data$value)), .data$value),
) %>%
dplyr::right_join(ds_eav_possible, by = c("record", "event_id", "field_name"))

Expand Down

0 comments on commit e0d238d

Please sign in to comment.