Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active August 7, 2016 08:16
Show Gist options
  • Save artemklevtsov/87ad58743751a152a29f to your computer and use it in GitHub Desktop.
Save artemklevtsov/87ad58743751a152a29f to your computer and use it in GitHub Desktop.
# Convert camelCase character vector to separated
to_separated <- function(x, sep = ".") {
x <- gsub("(.)([[:upper:]][[:lower:]]+)", paste0("\\1", sep, "\\2"), x)
x <- gsub("([[:lower:][:digit:]])([[:upper:]])", paste0("\\1", sep, "\\2"), x)
x <- gsub(paste0("\\", sep, "+"), sep, x)
tolower(x)
}
# Convert separated character vector to camelCase
to_camel <- function(x) {
gsub("([^[:alnum:]])([[:alnum:]])", "\\U\\2", x, perl = TRUE)
}
# Capitalize character vector
capitalize <- function(x) {
gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", x, perl = TRUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment