From 16fbe86d8beca97bad64c324f453716e185ddab4 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Sat, 15 Jul 2023 15:06:05 -0500 Subject: [PATCH] back to regexes ref #504 --- R/metadata-utilities.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/R/metadata-utilities.R b/R/metadata-utilities.R index a5c5c7a2..9ebff6c9 100644 --- a/R/metadata-utilities.R +++ b/R/metadata-utilities.R @@ -111,18 +111,25 @@ regex_named_captures <- function(pattern, text, perl = TRUE) { } #' @rdname metadata_utilities +#' @importFrom rlang .data #' @export checkbox_choices <- function(select_choices) { checkmate::assert_character(select_choices, any.missing=FALSE, len=1, min.chars=1) + pattern <- "^(.+?),\\s*+(.*)$" + select_choices %>% strsplit(split = "|", fixed = TRUE) %>% magrittr::extract2(1) %>% - I() %>% - readr::read_csv( - col_names = c("id", "label"), - col_types = "cc" + base::trimws() %>% + tibble::as_tibble() %>% # default column name is `value` + dplyr::filter(.data$value != "") %>% + dplyr::transmute( + id = sub(pattern, "\\1", .data$value, perl = TRUE), + label = sub(pattern, "\\2", .data$value, perl = TRUE), ) + # pattern_checkboxes <- "(?<=\\A| \\| |\\| )(?\\d{1,}), (?