File: utils_names.R

package info (click to toggle)
r-cran-ggvis 0.4.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,716 kB
  • sloc: sh: 25; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 451 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
}