R Under development (unstable) (2023-11-16 r85542 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("R.utils") Loading required package: R.oo Loading required package: R.methodsS3 R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help. R.oo v1.25.0 (2022-06-12 02:20:02 UTC) successfully loaded. See ?R.oo for help. Attaching package: 'R.oo' The following object is masked from 'package:R.methodsS3': throw The following objects are masked from 'package:methods': getClasses, getMethods The following objects are masked from 'package:base': attach, detach, load, save R.utils v2.12.3 successfully loaded. See ?R.utils for help. Attaching package: 'R.utils' The following object is masked from 'package:utils': timestamp The following objects are masked from 'package:base': cat, commandArgs, getOption, isOpen, nullfile, parse, warnings > > strings <- list( + "", + "hello world" = c("helloWorld", "HelloWorld", "helloWorld", "HelloWorld"), + "tcn start" = c("tcnStart", "TcnStart", "tcnStart", "TcnStart"), + "GEO Accession" = c("gEOAccession", "GEOAccession", "geoAccession", "GEOAccession") + ) > > for (s in names(strings)) { + printf("Original: %s\n", sQuote(s)) + + y <- toCamelCase(s) + printf("Camel case: %s\n", sQuote(y)) + stopifnot(y == strings[[s]][1L]) + + y <- toCamelCase(s, capitalize=TRUE) + printf("Capitalized camel case: %s\n", sQuote(y)) + stopifnot(y == strings[[s]][2L]) + + y <- toCamelCase(s, preserveSameCase=TRUE) + printf("Capitalized camel case without same case preserved: %s\n", sQuote(y)) + stopifnot(y == strings[[s]][3L]) + + y <- toCamelCase(s, capitalize=TRUE, preserveSameCase=TRUE) + printf("Capitalized camel case with same case preserved: %s\n", sQuote(y)) + stopifnot(y == strings[[s]][4L]) + + cat("\n") + } Original: '' Camel case: '' Capitalized camel case: '' Capitalized camel case without same case preserved: '' Capitalized camel case with same case preserved: '' Original: 'hello world' Camel case: 'helloWorld' Capitalized camel case: 'HelloWorld' Capitalized camel case without same case preserved: 'helloWorld' Capitalized camel case with same case preserved: 'HelloWorld' Original: 'tcn start' Camel case: 'tcnStart' Capitalized camel case: 'TcnStart' Capitalized camel case without same case preserved: 'tcnStart' Capitalized camel case with same case preserved: 'TcnStart' Original: 'GEO Accession' Camel case: 'gEOAccession' Capitalized camel case: 'GEOAccession' Capitalized camel case without same case preserved: 'geoAccession' Capitalized camel case with same case preserved: 'GEOAccession' > > # Vectorized > s <- names(strings) > y <- toCamelCase(s) > stopifnot(length(y) == length(s)) > y0 <- sapply(strings, FUN=function(s) s[1L]) > stopifnot(all(y == y0)) > > # Empty vector > y <- toCamelCase(character(0L)) > stopifnot(length(y) == 0L) > y <- toCamelCase(NULL) > stopifnot(length(y) == 0L) > > # Missing values > for (preserveSameCase in c(FALSE, TRUE)) { + y <- toCamelCase(NA_character_, preserveSameCase=preserveSameCase) + stopifnot(is.na(y)) + + y <- toCamelCase(c(NA_character_, NA_character_), preserveSameCase=preserveSameCase) + stopifnot(all(is.na(y))) + + y <- toCamelCase(c(NA_character_, "hello world", NA_character_), preserveSameCase=preserveSameCase) + stopifnot(identical(y, c(NA_character_, "helloWorld", NA_character_))) + } > > > proc.time() user system elapsed 0.31 0.07 0.37