From a5ec52bdbb4a4bad2a662b47b7dafffb63b74a06 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Sun, 26 Feb 2017 02:07:02 -0600 Subject: [PATCH] Regex to pull out checkbox values. Proof-of-concept -not generalized. See #138 --- playgrounds/eav-playground.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/playgrounds/eav-playground.R b/playgrounds/eav-playground.R index 4d664a5e..266fde28 100644 --- a/playgrounds/eav-playground.R +++ b/playgrounds/eav-playground.R @@ -42,8 +42,8 @@ ds_eav <- readr::read_csv(raw_text) # ---- tweak-data -------------------------------------------------------------- -# ds_checkbox <- ds_metadata %>% -# dplyr::filter(field_type=="checkbox") +ds_checkbox <- ds_metadata %>% + dplyr::filter(field_type=="checkbox") ds_eav_2 <- ds_eav %>% dplyr::left_join( @@ -75,6 +75,16 @@ ds_2 <- ds %>% .funs = function(x) !is.na(x) # If there's any value, then it's TRUE. Missingness is converted to FALSE. ) +strsplit(ds_checkbox$select_choices_or_calculations[[1]], split="\\s*\\|\\s*", perl=F)[[1]] + +checkbox_ids <- + ds_checkbox$select_choices_or_calculations[1] %>% + strsplit( split="\\s*\\|\\s*", perl=F) %>% + .[[1]] %>% + gsub("(\\d{1,}),\\s*.+", "\\1", ., perl=T) %>% + as.integer() + + # ---- verify-values ----------------------------------------------------------- setdiff(colnames(ds_expected), colnames(ds_2)) setdiff(colnames(ds_2), colnames(ds_expected))