-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_format.R
More file actions
executable file
·30 lines (28 loc) · 907 Bytes
/
string_format.R
File metadata and controls
executable file
·30 lines (28 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
##FUNCTIONS
#' Convert strings to lowercase in a smart way.
#'
#' @param x A \code{character} string.
#' @param sep A \code{character} vector to specify multiple separator to remove
#' during lowercase conversion (Default: sep = c(" ", "_")).
#' @value A \code{character} string converted in lowercase.
#' @author Yoann Pageaud.
#' @export
#' @examples
#' @references
smart.tolower <- function(x, sep = c(" ", "_")){
#Split words
lapply(X = sep, FUN = function(i){
x <<- unlist(strsplit(x, i))
})
#Check if a word is a roman number
is.roman <- grepl(pattern = "^[IVMCXLD]{1}[IVMCXLD]+$", x = x)
#Convert
s <- vapply(
X = seq_along(x), USE.NAMES = FALSE, FUN.VALUE = character(length = 1),
FUN = function(i){
if(!is.roman[i]){
paste(substring(x[i], 1, 1), tolower(substring(x[i], 2)), sep = "")
} else { x[i] }
})
paste(s, collapse = sep)
}