Skip to content

Commit

Permalink
Update mx_syntax.R
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoxiangLi committed Oct 3, 2024
1 parent 8289b81 commit 47d6db9
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions R/mx_syntax.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#' }
#'
mx_caps <- function(x) {

x_v <- stringr::str_to_lower(x) |>
stringr::str_split(stringr::boundary()) |>
unlist()
Expand All @@ -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 = "")
Expand All @@ -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)

}


Expand All @@ -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)

}


Expand All @@ -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}")
})
})

Expand All @@ -131,7 +122,4 @@ fix_near <- function(x) {
}

return(x_clean)

}


0 comments on commit 47d6db9

Please sign in to comment.