R/utils_names.R

Defines functions capitalise under_score camelCase

camelCase <- function(x) {
  words <- strsplit(x, "_")
  
  caps <- lapply(words, function(x) {
    if (length(x) == 1) return(x)
    x[-1] <- capitalise(x[-1])
    x
  })
  
  vapply(caps, paste0, collapse = "", FUN.VALUE = character(1))
}

under_score <- function(x) {
  substr(x, 1, 1) <- tolower(substr(x, 1, 1))
  tolower(gsub("([A-Z])", "_\\1", x))
}

capitalise <- function(x, first = TRUE) {
  substr(x, 1, 1) <- toupper(substr(x, 1, 1))
  x
}

Try the ggvis package in your browser

Any scripts or data that you put into this service are public.

ggvis documentation built on May 29, 2024, 1:12 a.m.