diff --git a/R/mx_syntax.R b/R/mx_syntax.R index fce11a1..8e5bad6 100644 --- a/R/mx_syntax.R +++ b/R/mx_syntax.R @@ -22,7 +22,6 @@ #' } #' mx_caps <- function(x) { - x_v <- stringr::str_to_lower(x) |> stringr::str_split(stringr::boundary()) |> unlist() @@ -31,7 +30,7 @@ mx_caps <- function(x) { if (x_v[position] == " ") { next } - x_v[position] <- paste0("[",stringr::str_to_upper(x_v[position]),x_v[position],"]") + x_v[position] <- paste0("[", stringr::str_to_upper(x_v[position]), x_v[position], "]") } x_v <- paste0(x_v, collapse = "") @@ -50,40 +49,35 @@ mx_caps <- function(x) { #' term. #' @keywords internal -fix_caps <- function(x){ - - x_clean <- lapply(x, function(y){ - - purrr::map_chr(y, function(z){ - - # Stop if first character in string is square-brackets - if (grepl("\\[",substr(z,1,1))==TRUE) { - return(z) - } - - z_v <- stringr::str_squish(z) %>% - lapply(function(z) { - paste0("[", - toupper(substr(z, 1, 1)), - tolower(substr(z, 1, 1)), - "]", - substr(z, 2, nchar(z))) - }) %>% - unlist() - - return(z_v) - }) - - } - - ) +fix_caps <- function(x) { + x_clean <- lapply(x, function(y) { + purrr::map_chr(y, function(z) { + # Stop if first character in string is square-brackets + if (grepl("\\[", substr(z, 1, 1)) == TRUE) { + return(z) + } + + z_v <- stringr::str_squish(z) %>% + lapply(function(z) { + paste0( + "[", + toupper(substr(z, 1, 1)), + tolower(substr(z, 1, 1)), + "]", + substr(z, 2, nchar(z)) + ) + }) %>% + unlist() + + return(z_v) + }) + }) if (!is.list(x)) { x_clean <- unlist(x_clean) } return(x_clean) - } @@ -94,20 +88,18 @@ fix_caps <- function(x){ #' @keywords internal fix_wildcard <- function(x) { - x_clean <- lapply(x, function(y) { - purrr::map_chr(y, function(z) { + purrr::map_chr(y, function(z) { stringr::str_replace_all(z, "\\*", "([[:alpha:]])") }) }) -if (!is.list(x)) { - x_clean <- unlist(x_clean) -} + if (!is.list(x)) { + x_clean <- unlist(x_clean) + } return(x_clean) - } @@ -118,11 +110,10 @@ if (!is.list(x)) { #' @keywords internal fix_near <- function(x) { - x_clean <- lapply(x, function(y) { purrr::map_chr(y, function(z) { - stringr::str_replace_all(z,"\\s?[Nn][Ee][Aa][Rr](\\d)\\s?","NEAR\\1") %>% - stringr::str_replace_all("NEAR(\\d)","(\\\\s+)([[:graph:]]+\\\\s+){0,\\1}") + stringr::str_replace_all(z, "\\s?[Nn][Ee][Aa][Rr](\\d)\\s?", "NEAR\\1") %>% + stringr::str_replace_all("NEAR(\\d)", "(\\\\s+)([[:graph:]]+\\\\s+){0,\\1}") }) }) @@ -131,7 +122,4 @@ fix_near <- function(x) { } return(x_clean) - } - -