snakecase/ 0000755 0001762 0000144 00000000000 13472343233 012213 5 ustar ligges users snakecase/inst/ 0000755 0001762 0000144 00000000000 13472330271 013166 5 ustar ligges users snakecase/inst/doc/ 0000755 0001762 0000144 00000000000 13472330271 013733 5 ustar ligges users snakecase/inst/doc/introducing-the-snakecase-package.R 0000644 0001762 0000144 00000002204 13472330271 022503 0 ustar ligges users ## ----setup, include=FALSE------------------------------------------------
knitr::opts_chunk$set(echo = TRUE,
comment = "#>",
collapse = TRUE
)
## ------------------------------------------------------------------------
string <- c("lowerCamelCase", "ALL_CAPS", "IDontKNOWWhat_thisCASE_is")
## ------------------------------------------------------------------------
library(snakecase)
to_snake_case(string)
## ------------------------------------------------------------------------
to_mixed_case(string, sep_out = " ")
## ------------------------------------------------------------------------
to_snake_case(string, sep_out = ".")
to_snake_case(string, sep_out = "-")
## ------------------------------------------------------------------------
to_screaming_snake_case(string, sep_out = "=")
## ------------------------------------------------------------------------
to_upper_camel_case(string)
## ------------------------------------------------------------------------
library(magrittr)
to_any_case(c("SomeBAdInput", "someGoodInput")) %>% dput()
snakecase/inst/doc/caseconverters.Rmd 0000644 0001762 0000144 00000003052 13420607650 017426 0 ustar ligges users ---
title: "Case converters"
author: "Malte Grosser"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Caseconverters}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
## Basic examples
Default case is snake case
```{r, collapse = TRUE}
library(snakecase)
to_any_case("veryComplicatedString")
```
Of course other cases are supported (`case`) and separators can be adjusted (`sep_out`)
```{r, collapse = TRUE}
to_any_case(names(iris), sep_in = "\\.", case = "upper_camel", sep_out = " ")
```
And you might want to remove special characters along the way
```{r, collapse = TRUE}
to_any_case("Doppelgänger is originally german",
transliterations = "german", case = "upper_camel")
```
All of the cases like: snake, lower_camel, upper_camel, all_caps, lower_upper, upper_lower, mixed and sentence are based on parsed case
```{r, collapse = TRUE}
to_any_case("THISIsHOW IAmPARSED!", case = "parsed")
```
Shortcut wrappers like `to_snake_case`, `to_lower_camel_case` etc. are available.
Be aware that automatic case conversion depends on the input string and it is recommended to verify the results. So you might want to pipe these into `dput()` and hardcode name changes instead of blindly trusting `to_any_case()`'s output:
```{r, collapse = TRUE}
dput(to_any_case(c("SomeBAdInput", "someGoodInput")))
```
If you are interested in the design of this package, you can find more information on its [github page](https://github.com/Tazinho/snakecase). snakecase/inst/doc/introducing-the-snakecase-package.Rmd 0000644 0001762 0000144 00000006604 13471335326 023041 0 ustar ligges users ---
title: "Introducing the snakecase package"
author: "Malte Grosser"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introducing the snakecase package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
comment = "#>",
collapse = TRUE
)
```
There are many style guides out there which recommend specific naming conventions for programming languages. At 2017’s useR conference Rasmus Bååth showed quite impressively the variety of cases which even exist within base R in his talk ["The current state of naming conventions in R"](https://www.youtube.com/watch?v=Pv5dfsHBBKE).
However, consistent style is not only about naming new objects.
## Import
When you do a data analysis, most of the data already exists and you import it from disk, an API or a database. Here is the first moment in your data analysis when you have to decide if you want to rename your data or leave it as it is.
Let’s say you have some data named in any of the following conventions
```{r}
string <- c("lowerCamelCase", "ALL_CAPS", "IDontKNOWWhat_thisCASE_is")
```
You can now easily convert this string for example to snake case via
```{r}
library(snakecase)
to_snake_case(string)
```
## Graphics
Whenever you want to construct a graphic and you don’t like your conventions to come up in it, you can easily convert strings to a more humanly readable output like
```{r}
to_mixed_case(string, sep_out = " ")
```
You might have noticed the `sep_out` argument. This allows you to combine any case with any output separator to create other well known cases like
```{r}
to_snake_case(string, sep_out = ".")
to_snake_case(string, sep_out = "-")
```
or completely new ones like
```{r}
to_screaming_snake_case(string, sep_out = "=")
```
## Export
Finally, when you are done with your analysis and want to write data back into a .CSV file or your customers database, which has a camel case convention, you can just use
```{r}
to_upper_camel_case(string)
```
## Further information
The snakecase package goes quite deep into the little quirks which arise in automatic case conversion. However, it is well tweaked, to handle almost every edge case in an intuitive and elegant manner.
To get a complete overview of its functionality like other cases, handling of abbreviations, special input characters, different parsing options, transliterations and more, I recommend you to have a look into the quite extensive [readme on its github repository](https://github.com/Tazinho/snakecase).
As the package is relatively small and basically consists of its workhorse function `to_any_case()`, I can also react quite fast on new [issues](https://github.com/Tazinho/snakecase/issues).
And of course I [tweet](https://twitter.com/malte_grosser) occasionally about new functionality.
To round this up let me give you one advice about best practices: be aware that automatic case conversion depends on the input string and it is recommended to verify the results. Hence you might want to pipe them into `dput()` and hard-code name changes instead of blindly trusting the output
```{r}
library(magrittr)
to_any_case(c("SomeBAdInput", "someGoodInput")) %>% dput()
```
Happy snakecasing everyone ;) snakecase/inst/doc/caseconverters.R 0000644 0001762 0000144 00000001365 13472330270 017110 0 ustar ligges users ## ---- collapse = TRUE----------------------------------------------------
library(snakecase)
to_any_case("veryComplicatedString")
## ---- collapse = TRUE----------------------------------------------------
to_any_case(names(iris), sep_in = "\\.", case = "upper_camel", sep_out = " ")
## ---- collapse = TRUE----------------------------------------------------
to_any_case("Doppelgänger is originally german",
transliterations = "german", case = "upper_camel")
## ---- collapse = TRUE----------------------------------------------------
to_any_case("THISIsHOW IAmPARSED!", case = "parsed")
## ---- collapse = TRUE----------------------------------------------------
dput(to_any_case(c("SomeBAdInput", "someGoodInput")))
snakecase/inst/doc/caseconverters.html 0000644 0001762 0000144 00000027232 13472330270 017654 0 ustar ligges users
Case converters
Case converters
Malte Grosser
2019-05-25
Basic examples
Default case is snake case
Of course other cases are supported (case
) and separators can be adjusted (sep_out
)
And you might want to remove special characters along the way
All of the cases like: snake, lower_camel, upper_camel, all_caps, lower_upper, upper_lower, mixed and sentence are based on parsed case
Shortcut wrappers like to_snake_case
, to_lower_camel_case
etc. are available.
Be aware that automatic case conversion depends on the input string and it is recommended to verify the results. So you might want to pipe these into dput()
and hardcode name changes instead of blindly trusting to_any_case()
’s output:
If you are interested in the design of this package, you can find more information on its github page.
snakecase/inst/doc/introducing-the-snakecase-package.html 0000644 0001762 0000144 00000035743 13472330271 023264 0 ustar ligges users
Introducing the snakecase package
Introducing the snakecase package
Malte Grosser
2019-05-25
There are many style guides out there which recommend specific naming conventions for programming languages. At 2017’s useR conference Rasmus Bååth showed quite impressively the variety of cases which even exist within base R in his talk “The current state of naming conventions in R”.
However, consistent style is not only about naming new objects.
Import
When you do a data analysis, most of the data already exists and you import it from disk, an API or a database. Here is the first moment in your data analysis when you have to decide if you want to rename your data or leave it as it is.
Let’s say you have some data named in any of the following conventions
You can now easily convert this string for example to snake case via
Graphics
Whenever you want to construct a graphic and you don’t like your conventions to come up in it, you can easily convert strings to a more humanly readable output like
You might have noticed the sep_out
argument. This allows you to combine any case with any output separator to create other well known cases like
or completely new ones like
Export
Finally, when you are done with your analysis and want to write data back into a .CSV file or your customers database, which has a camel case convention, you can just use
snakecase/tests/ 0000755 0001762 0000144 00000000000 13420607650 013354 5 ustar ligges users snakecase/tests/testthat.R 0000644 0001762 0000144 00000000131 13420607650 015332 0 ustar ligges users library("testthat")
library("tibble")
library("snakecase")
test_check("snakecase") snakecase/tests/testthat/ 0000755 0001762 0000144 00000000000 13472343233 015215 5 ustar ligges users snakecase/tests/testthat/test-to_title_case.R 0000644 0001762 0000144 00000000742 13467512544 021145 0 ustar ligges users context("to_title_case")
test_that("title case", {
expect_equal(
to_title_case(c("on_andOn", "AndON", " and on", "and so on", "seems like it works", "also abbreviations ETC"), abbreviations = "ETC"),
c("On and on", "And on", "And on", "And so on", "Seems Like it Works", "Also Abbreviations ETC")
)
})
test_that("title case and abbreviations", {
expect_equal(
to_title_case("so sieht es aus", abbreviations = "ES"),
"So Sieht ES Aus"
)
}) snakecase/tests/testthat/test-to_parsed_case_internal.R 0000644 0001762 0000144 00000001476 13472126201 023166 0 ustar ligges users context("to_parsed_case_internal")
test_that("condition 6", {
expect_error(to_parsed_case_internal("bla", parsing_option = 7),
"parsing_option must be between -4 and +4.", fixed = TRUE)}
)
test_that("parsing_option -1", {
expect_equal(to_parsed_case_internal("look_AfterThe-hyphen andThe.dot", parsing_option = -1, numerals = "asis", abbreviations = NULL, sep_in = NULL),
"look_After_The-hyphen and_The.dot")}
)
test_that("all", {
expect_equal(to_parsed_case_internal(string = "bla", numerals = "asis", parsing_option = 2, sep = "_", abbreviations = NULL),
"bla")
}
)
test_that("split", {
expect_equal(to_parsed_case_internal("bla_ lbla", abbreviations = NULL, sep_in =NULL, numerals = "middle")
,
"bla_ _lbla")
}
) snakecase/tests/testthat/test-to_lower_camel_case.R 0000644 0001762 0000144 00000002367 13472123712 022311 0 ustar ligges users context("to_lower_camel_case")
test_that("examples", {
expect_equal(to_lower_camel_case(cases[["examples"]]),
cases[["small_camel_case"]])}
)
test_that("rules",{
examples <- cases[["examples"]]
expect_equal(to_lower_camel_case(to_snake_case(examples)),
to_lower_camel_case(examples)
)
expect_equal(to_lower_camel_case(to_lower_camel_case(examples)),
to_lower_camel_case(examples)
)
expect_equal(to_lower_camel_case(to_upper_camel_case(examples)),
to_lower_camel_case(examples)
)
expect_equal(to_lower_camel_case(to_screaming_snake_case(examples)),
to_lower_camel_case(examples)
)
expect_equal(to_lower_camel_case(to_parsed_case(examples)),
to_lower_camel_case(examples)
)
})
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_lower_camel_case(labs),
structure(c("abcDef", "bbccEe", "teEStIt"), .Names = c("a", "b",
"c"))
)
})
test_that("abbreviations", {
expect_equal(to_lower_camel_case("t2d_status", abbreviations = "t2d"),
"t2dStatus")
}) snakecase/tests/testthat/test-to_screaming_snake_case.R 0000644 0001762 0000144 00000002242 13420607650 023142 0 ustar ligges users context("to_screaming_snake_case")
test_that("examples", {
expect_equal(to_screaming_snake_case(cases[["examples"]]),
cases[["screaming_snake_case"]])}
)
test_that("rules",{
examples <- cases[["examples"]]
expect_equal(to_screaming_snake_case(to_snake_case(examples)),
to_screaming_snake_case(examples)
)
expect_equal(to_screaming_snake_case(to_lower_camel_case(examples)),
to_screaming_snake_case(examples)
)
expect_equal(to_screaming_snake_case(to_upper_camel_case(examples)),
to_screaming_snake_case(examples)
)
expect_equal(to_screaming_snake_case(to_screaming_snake_case(examples)),
to_screaming_snake_case(examples)
)
expect_equal(to_screaming_snake_case(to_parsed_case(examples)),
to_screaming_snake_case(examples)
)
})
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_screaming_snake_case(labs),
structure(c("ABC_DEF", "BBCC_EE", "TE_E_ST_IT"), .Names = c("a",
"b", "c"))
)
}) snakecase/tests/testthat/test-to_any_case.R 0000644 0001762 0000144 00000160534 13472265400 020611 0 ustar ligges users context("to_any_case")
test_that("examples", {
examples <- cases[["examples"]]
expect_equal(to_any_case(examples, case = "snake"),
cases[["snake_case"]])
expect_equal(to_any_case(examples, case = "small_camel"),
cases[["small_camel_case"]])
expect_equal(to_any_case(examples, case = "big_camel"),
cases[["big_camel_case"]])
expect_equal(to_any_case(examples, case = "screaming_snake"),
cases[["screaming_snake_case"]])
expect_equal(to_any_case(examples, case = "parsed"),
cases[["parsed_case"]])
expect_equal(to_any_case("R.Studio", case = "big_camel", sep_out = "-"),
"R-Studio")
expect_equal(to_any_case("HAMBURGcity", case = "parsed", parsing_option = 0),
"HAMBURGcity")
expect_equal(to_any_case(c("RSSfeedRSSfeed", "USPassport", "USpassport"), abbreviations = c("RSS", "US")),
c("rss_feed_rss_feed", "us_passport", "us_passport"))
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "parsed"),
"NBA_Game")
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "mixed"),
"NBA_Game")
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "snake"),
"nba_game")
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "screaming_snake"),
"NBA_GAME")
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "internal_parsing"),
"NBA_Game")
expect_equal(to_any_case("NBAGame", abbreviations = "NBA", case = "upper_camel"),
"NBAGame")
expect_equal(to_any_case("nba_game", abbreviations = "NBA", case = "lower_camel"),
"nbaGame")
expect_equal(to_any_case("NBA_game", abbreviations = "NBA", case = "upper_camel"),
"NBAGame")
expect_equal(to_any_case("nba_game", abbreviations = "NBA", case = "upper_camel"),
"NBAGame")
expect_equal(to_any_case("NBA_game_NBA", abbreviations = "NBA", case = "lower_camel"),
"nbaGameNBA")
expect_equal(to_any_case("NBA_game_NBA", abbreviations = "NBA", case = "lower_upper"),
"nbaGAMEnba")
expect_equal(to_any_case("NBA_game", abbreviations = "NBA", case = "mixed"),
"NBA_game")
expect_equal(to_any_case("NBA_game_NBA", abbreviations = "NBA", case = "mixed"),
"NBA_game_NBA")
expect_equal(to_snake_case(c("NBAGame", "NBAgame"), abbreviations = "NBA"),
c("nba_game", "nba_game"))
expect_equal(to_upper_camel_case(c("nba_game", "nba_game"), abbreviations = "NBA"),
c("NBAGame", "NBAGame"))
}
)
test_that("numerals_tight",
{
expect_equal(to_any_case("bla_la_123_123_1_bla", numerals = "tight"),
"bla_la123_123_1bla")
})
test_that("attributes", {
expect_equal(
{strings <- c("this Is a Strange_string", "AND THIS ANOTHER_One");
names(strings) <- c("String A", "String B");
attr(strings, "test.attr") <- "test";
strings},
structure(c(`String A` = "this Is a Strange_string", `String B` = "AND THIS ANOTHER_One"),
test.attr = "test"))
}
)
test_that("numerals", {
expect_equal(to_any_case("123bla123bla_434bla"),
"123_bla_123_bla_434_bla")
expect_equal(to_any_case("123bla123bla_434bla",
numerals = "asis"),
"123bla123bla_434bla")
expect_equal(to_any_case("123bla123bla_434bla",
numerals = "left"),
"123_bla123_bla434_bla")
expect_equal(to_any_case("123bla123bla_434bla",
numerals = "right"),
"123bla_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "middle"),
"123_bla_123_123_bla_434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "asis"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "left"),
"123_bla123_123_bla434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
numerals = "right"),
"123bla_123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "right"),
"123bla_123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "right"),
"123bla_123_123bla_434bla")
expect_equal(to_upper_camel_case("123bla123_123bla_434bla"),
"123Bla123_123Bla434Bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "upper_camel", numerals = "middle"),
"123Bla123_123Bla434Bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "upper_camel", numerals = "asis"), "123Bla123_123Bla434Bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "upper_camel", numerals = "left"),
"123Bla123_123Bla434Bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "upper_camel", numerals = "right"),
"123Bla123_123Bla434Bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "parsed", numerals = "middle"),
"123_bla_123_123_bla_434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "parsed", numerals = "asis"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla", case = "parsed", numerals = "left"),
"123_bla123_123_bla434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
case = "parsed",
numerals = "right"),
"123bla_123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
case = "none",
numerals = "middle"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
case = "none",
numerals = "asis"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
case = "none",
numerals = "left"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
case = "none",
numerals = "right"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
numerals = "middle"),
"123_bla_123_123_bla_434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla", numerals = "asis"),
"123bla123_123bla_434bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
numerals = "left"),
"123_bla123_123_bla434_bla")
expect_equal(to_any_case("123bla123_123bla_434bla",
numerals = "right"),
"123bla_123_123bla_434bla")
expect_equal(to_any_case("species42value 23month",
numerals = "asis"),
"species42value_23month")
expect_equal(to_any_case(c("HHcity", "IDtable1", "KEYtable2", "newUSelections"),
parsing_option = 2,
numerals = "middle"),
c("hh_city", "id_table_1", "key_table_2", "new_us_elections"))
expect_equal(to_any_case(c("HHcity", "IDtable1", "KEYtable2", "newUSelections"),
parsing_option = 2,
numerals = "asis"),
c("hh_city","id_table1", "key_table2", "new_us_elections"))
expect_equal(to_any_case(c("HHcity", "IDtable1", "KEYtable2", "newUSelections"), parsing_option = 2, numerals = "left"),
c("hh_city", "id_table1", "key_table2","new_us_elections"))
expect_equal(to_any_case(c("HHcity", "IDtable1", "KEYtable2", "newUSelections"),
parsing_option = 2,
numerals = "right"),
c("hh_city", "id_table_1", "key_table_2",
"new_us_elections"))
})
test_that("preserve-names-attribute", {
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_any_case(labs, case = "snake"),
structure(c("abc_def", "bbcc_ee", "te_e_st_it"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "upper_camel"),
structure(c("AbcDef", "BbccEe", "TeEStIt"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "lower_camel"),
structure(c("abcDef", "bbccEe", "teEStIt"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "parsed"),
structure(c("abc_DEF", "bbcc_EE", "Te_E_St_it"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "mixed"),
structure(c("abc_Def", "bbcc_Ee", "Te_E_St_it"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "none", sep_in = NULL),
structure(c("abcDEF", "bbccEE", "TeESt it"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "all_caps"),
structure(c("ABC_DEF", "BBCC_EE", "TE_E_ST_IT"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "upper_lower"),
structure(c("ABCdef", "BBCCee", "TEeSTit"), .Names = c("a", "b", "c"))
)
expect_equal(
to_any_case(labs, case = "lower_upper"),
structure(c("abcDEF", "bbccEE", "teEstIT"), .Names = c("a", "b", "c"))
)
})
test_that("uniqe_sep", {
expect_equal(
to_any_case(c("bla", "bla"), unique_sep = "_"),
c("bla", "bla_1")
)
expect_equal(
to_any_case(c("bla", "bla"), unique_sep = NULL),
c("bla", "bla")
)
})
test_that("sentence_case", {
expect_equal(
to_sentence_case("this_is_a_sentence", sep_out = " ", postfix = "."),
"This is a sentence.")
})
test_that("janitor-pkg-tests",{
skip_if_not( l10n_info()$`UTF-8`)
clean_names3 <- function(old_names, case = "snake"){
new_names <- gsub("'", "", old_names) # remove quotation marks
new_names <- gsub("\"", "", new_names) # remove quotation marks
new_names <- gsub("%", ".percent_", new_names)
new_names <- gsub("#", ".number_", new_names)
new_names <- gsub("^[[:space:][:punct:]]+", "", new_names)
new_names <- make.names(new_names)
new_names <- to_any_case(new_names, case = case, sep_in = "\\.",
transliterations = c("Latin-ASCII"), parsing_option = 1, numerals = "asis")
# Handle duplicated names - they mess up dplyr pipelines
# This appends the column number to repeated instances of duplicate variable names
dupe_count <- vapply(1:length(new_names), function(i) {
sum(new_names[i] == new_names[1:i]) }, integer(1))
new_names[dupe_count > 1] <- paste(new_names[dupe_count > 1],
dupe_count[dupe_count > 1],
sep = "_")
new_names
}
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143")),
c("sp_ace", "repeated", "a", "percent", "x", "x_2", "d_9", "repeated_2",
"cant", "hi_there", "leading_spaces", "x_3", "acao", "faroe",
"r_studio_v_1_0_143"))
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "parsed"),
c("sp_ace", "repeated", "a", "percent", "X", "X_2", "d_9", "REPEATED",
"cant", "hi_there", "leading_spaces", "X_3", "acao", "faroe",
"r_studio_v_1_0_143"))
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "screaming_snake"),
c("SP_ACE", "REPEATED", "A", "PERCENT", "X", "X_2", "D_9", "REPEATED_2",
"CANT", "HI_THERE", "LEADING_SPACES", "X_3", "ACAO", "FAROE",
"R_STUDIO_V_1_0_143")
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "small_camel"),
c("spAce", "repeated", "a", "percent", "x", "x_2", "d9", "repeated_2",
"cant", "hiThere", "leadingSpaces", "x_3", "acao", "faroe", "rStudioV1_0_143"
)
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "big_camel"),
c("SpAce", "Repeated", "A", "Percent", "X", "X_2", "D9", "Repeated_2",
"Cant", "HiThere", "LeadingSpaces", "X_3", "Acao", "Faroe", "RStudioV1_0_143"
)
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "lower_upper"),
c("spACE", "repeated", "a", "percent", "x", "x_2", "d9", "repeated_2",
"cant", "hiTHERE", "leadingSPACES", "x_3", "acao", "faroe", "rSTUDIOv1_0_143"
)
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "upper_lower"),
c("SPace", "REPEATED", "A", "PERCENT", "X", "X_2", "D9", "REPEATED_2",
"CANT", "HIthere", "LEADINGspaces", "X_3", "ACAO", "FAROE", "RstudioV1_0_143"
)
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "mixed"),
c("sp_ace", "repeated", "a", "percent", "X", "X_2", "d_9", "Repeated",
"cant", "hi_there", "leading_spaces", "X_3", "acao", "faroe",
"r_studio_v_1_0_143")
)
expect_equal(clean_names3(c("sp ace", "repeated", "a**^@", "%", "*",
"!", "d(!)9", "REPEATED", "can\"'t", "hi_`there`",
" leading spaces", "\u20AC", "a\u00E7\u00E3o", "far\u0153", "r.st\u00FCdio:v.1.0.143"),
case = "none"),
c("sp_ace", "repeated", "a", "percent",
"X", "X_2", "d_9", "REPEATED",
"cant", "hi_there", "leading_spaces", "X_3",
"acao", "faroe", "r_studio_v_1_0_143")
)
})
# test_that("rules",{
# examples <- cases[["examples"]]
#
# expect_equal(to_snake_case(to_snake_case(examples)),
# to_snake_case(examples)
# )
# expect_equal(to_snake_case(to_small_camel_case(examples)),
# to_snake_case(examples)
# )
# expect_equal(to_snake_case(to_big_camel_case(examples)),
# to_snake_case(examples)
# )
# expect_equal(to_snake_case(to_screaming_snake_case(examples)),
# to_snake_case(examples)
# )
# })
test_that("random examples",
expect_equal(to_any_case("string123", case = "snake"),
"string_123"))
# test_that("deprecated",
# expect_warning(to_any_case("bla", protect = "_"),
# "argument protect is deprecated; If you really need this argument, pls submit an issue on https://github.com/Tazinho/snakecase")
# )
test_that("transliterations", {
skip_if_not( l10n_info()$`UTF-8`)
expect_equal(to_any_case("Älterer Herr", transliterations = c("german", "Herr" = "Mann")), "aelterer_mann")
expect_equal(
to_any_case("Älterer Herr", transliterations = c( "Herr" = "Mann", "german")),
"aelterer_mann")
})
test_that("transliterations_error",
expect_error(to_any_case("bla", transliterations = "bla"),
"Input to `transliterations` must be `NULL`, a string containing elements from the internal lookup dictionaries or from `stringi::stri_trans_list()` or a named vector.",
fixed = TRUE))
test_that("empty_fill",
expect_equal(to_any_case("", empty_fill = "bla"),
"bla"))
test_that("sentence",
expect_equal(to_any_case("bla bla_bal", case = "sentence"),
"Bla bla bal"))
test_that("flip and swap", {
expect_equal(to_any_case("rSTUDIO", case = "flip"), "Rstudio")
expect_equal(to_any_case("rSTUDIO", case = "swap"), "Rstudio")
})
test_that("complex strings", {
skip_if_not( l10n_info()$`UTF-8`)
strings2 <- c("this - Is_-: a Strange_string", "\u00C4ND THIS ANOTHER_One")
expect_equal(to_any_case(strings2, case = "snake", sep_in = "-|\\:"),
c("this_is_a_strange_string", "\u00E4nd_this_another_one"))
expect_equal(to_any_case("MERKWUERDIGER-VariablenNAME mit.VIELENMustern_version: 3.7.4",
case = "snake",
sep_in = "-|:|(?% dput
c(NA, "", "s_na_k_er", "SNAKE_SNAKE_CASE", "snake_Snak_E_Case",
"SNAKE_snak_E_case", "ss_R_Rss", "ss_RRRR", "this_Is_Some_Camel_Case",
"this.text", "final_count", "Bob_Dylan_USA", "Mikhail_Gorbachev_USSR",
"Helpful_Stack_Overflow_People", "Im_A_Tall_Drink_Of_Water",
"ICU_Days", "Sex_Code", "MAX_of_MLD", "Age.Group", NA, "",
"s_na_k_er", "snake_snake_case", "snake_snak_e_case", "snake_snak_e_case",
"ss_r_rss", "ss_rrrr", "this_is_some_camel_case", "this.text",
"final_count", "bob_dylan_usa", "mikhail_gorbachev_ussr", "helpful_stack_overflow_people",
"im_a_tall_drink_of_water", "icu_days", "sex_code", "max_of_mld",
"age.group", NA, "", "sNaKEr", "snakeSnakeCase", "snakeSnakECase",
"snakeSnakECase", "ssRRss", "ssRrrr", "thisIsSomeCamelCase",
"this.Text", "finalCount", "bobDylanUsa", "mikhailGorbachevUssr",
"helpfulStackOverflowPeople", "imATallDrinkOfWater", "icuDays",
"sexCode", "maxOfMld", "age.Group", NA, "", "SNaKEr", "SnakeSnakeCase",
"SnakeSnakECase", "SnakeSnakECase", "SsRRss", "SsRrrr", "ThisIsSomeCamelCase",
"This.Text", "FinalCount", "BobDylanUsa", "MikhailGorbachevUssr",
"HelpfulStackOverflowPeople", "ImATallDrinkOfWater", "IcuDays",
"SexCode", "MaxOfMld", "Age.Group", NA, "", "S_NA_K_ER", "SNAKE_SNAKE_CASE",
"SNAKE_SNAK_E_CASE", "SNAKE_SNAK_E_CASE", "SS_R_RSS", "SS_RRRR",
"THIS_IS_SOME_CAMEL_CASE", "THIS.TEXT", "FINAL_COUNT", "BOB_DYLAN_USA",
"MIKHAIL_GORBACHEV_USSR", "HELPFUL_STACK_OVERFLOW_PEOPLE", "IM_A_TALL_DRINK_OF_WATER",
"ICU_DAYS", "SEX_CODE", "MAX_OF_MLD", "AGE.GROUP", NA, ".end",
"s_na_k_er.end", "SNAKE_SNAKE_CASE.end", "snake_Snak_E_Case.end",
"SNAKE_snak_E_case.end", "ss_R_Rss.end", "ss_RRRR.end", "this_Is_Some_Camel_Case.end",
"this.text.end", "final_count.end", "Bob_Dylan_USA.end", "Mikhail_Gorbachev_USSR.end",
"Helpful_Stack_Overflow_People.end", "Im_A_Tall_Drink_Of_Water.end",
"ICU_Days.end", "Sex_Code.end", "MAX_of_MLD.end", "Age.Group.end",
NA, ".end", "s_na_k_er.end", "snake_snake_case.end", "snake_snak_e_case.end",
"snake_snak_e_case.end", "ss_r_rss.end", "ss_rrrr.end", "this_is_some_camel_case.end",
"this.text.end", "final_count.end", "bob_dylan_usa.end", "mikhail_gorbachev_ussr.end",
"helpful_stack_overflow_people.end", "im_a_tall_drink_of_water.end",
"icu_days.end", "sex_code.end", "max_of_mld.end", "age.group.end",
NA, ".end", "sNaKEr.end", "snakeSnakeCase.end", "snakeSnakECase.end",
"snakeSnakECase.end", "ssRRss.end", "ssRrrr.end", "thisIsSomeCamelCase.end",
"this.Text.end", "finalCount.end", "bobDylanUsa.end", "mikhailGorbachevUssr.end",
"helpfulStackOverflowPeople.end", "imATallDrinkOfWater.end",
"icuDays.end", "sexCode.end", "maxOfMld.end", "age.Group.end",
NA, ".end", "SNaKEr.end", "SnakeSnakeCase.end", "SnakeSnakECase.end",
"SnakeSnakECase.end", "SsRRss.end", "SsRrrr.end", "ThisIsSomeCamelCase.end",
"This.Text.end", "FinalCount.end", "BobDylanUsa.end", "MikhailGorbachevUssr.end",
"HelpfulStackOverflowPeople.end", "ImATallDrinkOfWater.end",
"IcuDays.end", "SexCode.end", "MaxOfMld.end", "Age.Group.end",
NA, ".end", "S_NA_K_ER.end", "SNAKE_SNAKE_CASE.end", "SNAKE_SNAK_E_CASE.end",
"SNAKE_SNAK_E_CASE.end", "SS_R_RSS.end", "SS_RRRR.end", "THIS_IS_SOME_CAMEL_CASE.end",
"THIS.TEXT.end", "FINAL_COUNT.end", "BOB_DYLAN_USA.end", "MIKHAIL_GORBACHEV_USSR.end",
"HELPFUL_STACK_OVERFLOW_PEOPLE.end", "IM_A_TALL_DRINK_OF_WATER.end",
"ICU_DAYS.end", "SEX_CODE.end", "MAX_OF_MLD.end", "AGE.GROUP.end",
NA, "start.", "start.s_na_k_er", "start.SNAKE_SNAKE_CASE", "start.snake_Snak_E_Case",
"start.SNAKE_snak_E_case", "start.ss_R_Rss", "start.ss_RRRR",
"start.this_Is_Some_Camel_Case", "start.this.text", "start.final_count",
"start.Bob_Dylan_USA", "start.Mikhail_Gorbachev_USSR", "start.Helpful_Stack_Overflow_People",
"start.Im_A_Tall_Drink_Of_Water", "start.ICU_Days", "start.Sex_Code",
"start.MAX_of_MLD", "start.Age.Group", NA, "start.", "start.s_na_k_er",
"start.snake_snake_case", "start.snake_snak_e_case", "start.snake_snak_e_case",
"start.ss_r_rss", "start.ss_rrrr", "start.this_is_some_camel_case",
"start.this.text", "start.final_count", "start.bob_dylan_usa",
"start.mikhail_gorbachev_ussr", "start.helpful_stack_overflow_people",
"start.im_a_tall_drink_of_water", "start.icu_days", "start.sex_code",
"start.max_of_mld", "start.age.group", NA, "start.", "start.sNaKEr",
"start.snakeSnakeCase", "start.snakeSnakECase", "start.snakeSnakECase",
"start.ssRRss", "start.ssRrrr", "start.thisIsSomeCamelCase",
"start.this.Text", "start.finalCount", "start.bobDylanUsa", "start.mikhailGorbachevUssr",
"start.helpfulStackOverflowPeople", "start.imATallDrinkOfWater",
"start.icuDays", "start.sexCode", "start.maxOfMld", "start.age.Group",
NA, "start.", "start.SNaKEr", "start.SnakeSnakeCase", "start.SnakeSnakECase",
"start.SnakeSnakECase", "start.SsRRss", "start.SsRrrr", "start.ThisIsSomeCamelCase",
"start.This.Text", "start.FinalCount", "start.BobDylanUsa", "start.MikhailGorbachevUssr",
"start.HelpfulStackOverflowPeople", "start.ImATallDrinkOfWater",
"start.IcuDays", "start.SexCode", "start.MaxOfMld", "start.Age.Group",
NA, "start.", "start.S_NA_K_ER", "start.SNAKE_SNAKE_CASE", "start.SNAKE_SNAK_E_CASE",
"start.SNAKE_SNAK_E_CASE", "start.SS_R_RSS", "start.SS_RRRR",
"start.THIS_IS_SOME_CAMEL_CASE", "start.THIS.TEXT", "start.FINAL_COUNT",
"start.BOB_DYLAN_USA", "start.MIKHAIL_GORBACHEV_USSR", "start.HELPFUL_STACK_OVERFLOW_PEOPLE",
"start.IM_A_TALL_DRINK_OF_WATER", "start.ICU_DAYS", "start.SEX_CODE",
"start.MAX_OF_MLD", "start.AGE.GROUP", NA, "start..end", "start.s_na_k_er.end",
"start.SNAKE_SNAKE_CASE.end", "start.snake_Snak_E_Case.end",
"start.SNAKE_snak_E_case.end", "start.ss_R_Rss.end", "start.ss_RRRR.end",
"start.this_Is_Some_Camel_Case.end", "start.this.text.end",
"start.final_count.end", "start.Bob_Dylan_USA.end", "start.Mikhail_Gorbachev_USSR.end",
"start.Helpful_Stack_Overflow_People.end", "start.Im_A_Tall_Drink_Of_Water.end",
"start.ICU_Days.end", "start.Sex_Code.end", "start.MAX_of_MLD.end",
"start.Age.Group.end", NA, "start..end", "start.s_na_k_er.end",
"start.snake_snake_case.end", "start.snake_snak_e_case.end",
"start.snake_snak_e_case.end", "start.ss_r_rss.end", "start.ss_rrrr.end",
"start.this_is_some_camel_case.end", "start.this.text.end",
"start.final_count.end", "start.bob_dylan_usa.end", "start.mikhail_gorbachev_ussr.end",
"start.helpful_stack_overflow_people.end", "start.im_a_tall_drink_of_water.end",
"start.icu_days.end", "start.sex_code.end", "start.max_of_mld.end",
"start.age.group.end", NA, "start..end", "start.sNaKEr.end",
"start.snakeSnakeCase.end", "start.snakeSnakECase.end", "start.snakeSnakECase.end",
"start.ssRRss.end", "start.ssRrrr.end", "start.thisIsSomeCamelCase.end",
"start.this.Text.end", "start.finalCount.end", "start.bobDylanUsa.end",
"start.mikhailGorbachevUssr.end", "start.helpfulStackOverflowPeople.end",
"start.imATallDrinkOfWater.end", "start.icuDays.end", "start.sexCode.end",
"start.maxOfMld.end", "start.age.Group.end", NA, "start..end",
"start.SNaKEr.end", "start.SnakeSnakeCase.end", "start.SnakeSnakECase.end",
"start.SnakeSnakECase.end", "start.SsRRss.end", "start.SsRrrr.end",
"start.ThisIsSomeCamelCase.end", "start.This.Text.end", "start.FinalCount.end",
"start.BobDylanUsa.end", "start.MikhailGorbachevUssr.end", "start.HelpfulStackOverflowPeople.end",
"start.ImATallDrinkOfWater.end", "start.IcuDays.end", "start.SexCode.end",
"start.MaxOfMld.end", "start.Age.Group.end", NA, "start..end",
"start.S_NA_K_ER.end", "start.SNAKE_SNAKE_CASE.end", "start.SNAKE_SNAK_E_CASE.end",
"start.SNAKE_SNAK_E_CASE.end", "start.SS_R_RSS.end", "start.SS_RRRR.end",
"start.THIS_IS_SOME_CAMEL_CASE.end", "start.THIS.TEXT.end",
"start.FINAL_COUNT.end", "start.BOB_DYLAN_USA.end", "start.MIKHAIL_GORBACHEV_USSR.end",
"start.HELPFUL_STACK_OVERFLOW_PEOPLE.end", "start.IM_A_TALL_DRINK_OF_WATER.end",
"start.ICU_DAYS.end", "start.SEX_CODE.end", "start.MAX_OF_MLD.end",
"start.AGE.GROUP.end", NA, "", "s_na_k_er", "SNAKE_SNAKE_CASE",
"snake_Snak_E_Case", "SNAKE_snak_E_case", "ss_R_Rss", "ss_RRRR",
"this_Is_Some_Camel_Case", "this.text", "final_count", "Bob_Dylan_USA",
"Mikhail_Gorbachev_USSR", "Helpful_Stack_Overflow_People", "Im_A_Tall_Drink_Of_Water",
"ICU_Days", "Sex_Code", "MAX_of_MLD", "Age.Group", NA, "",
"s_na_k_er", "snake_snake_case", "snake_snak_e_case", "snake_snak_e_case",
"ss_r_rss", "ss_rrrr", "this_is_some_camel_case", "this.text",
"final_count", "bob_dylan_usa", "mikhail_gorbachev_ussr", "helpful_stack_overflow_people",
"im_a_tall_drink_of_water", "icu_days", "sex_code", "max_of_mld",
"age.group", NA, "", "sNaKEr", "snakeSnakeCase", "snakeSnakECase",
"snakeSnakECase", "ssRRss", "ssRrrr", "thisIsSomeCamelCase",
"this.Text", "finalCount", "bobDylanUsa", "mikhailGorbachevUssr",
"helpfulStackOverflowPeople", "imATallDrinkOfWater", "icuDays",
"sexCode", "maxOfMld", "age.Group", NA, "", "SNaKEr", "SnakeSnakeCase",
"SnakeSnakECase", "SnakeSnakECase", "SsRRss", "SsRrrr", "ThisIsSomeCamelCase",
"This.Text", "FinalCount", "BobDylanUsa", "MikhailGorbachevUssr",
"HelpfulStackOverflowPeople", "ImATallDrinkOfWater", "IcuDays",
"SexCode", "MaxOfMld", "Age.Group", NA, "", "S_NA_K_ER", "SNAKE_SNAKE_CASE",
"SNAKE_SNAK_E_CASE", "SNAKE_SNAK_E_CASE", "SS_R_RSS", "SS_RRRR",
"THIS_IS_SOME_CAMEL_CASE", "THIS.TEXT", "FINAL_COUNT", "BOB_DYLAN_USA",
"MIKHAIL_GORBACHEV_USSR", "HELPFUL_STACK_OVERFLOW_PEOPLE", "IM_A_TALL_DRINK_OF_WATER",
"ICU_DAYS", "SEX_CODE", "MAX_OF_MLD", "AGE.GROUP", NA, ".end",
"s_na_k_er.end", "SNAKE_SNAKE_CASE.end", "snake_Snak_E_Case.end",
"SNAKE_snak_E_case.end", "ss_R_Rss.end", "ss_RRRR.end", "this_Is_Some_Camel_Case.end",
"this.text.end", "final_count.end", "Bob_Dylan_USA.end", "Mikhail_Gorbachev_USSR.end",
"Helpful_Stack_Overflow_People.end", "Im_A_Tall_Drink_Of_Water.end",
"ICU_Days.end", "Sex_Code.end", "MAX_of_MLD.end", "Age.Group.end",
NA, ".end", "s_na_k_er.end", "snake_snake_case.end", "snake_snak_e_case.end",
"snake_snak_e_case.end", "ss_r_rss.end", "ss_rrrr.end", "this_is_some_camel_case.end",
"this.text.end", "final_count.end", "bob_dylan_usa.end", "mikhail_gorbachev_ussr.end",
"helpful_stack_overflow_people.end", "im_a_tall_drink_of_water.end",
"icu_days.end", "sex_code.end", "max_of_mld.end", "age.group.end",
NA, ".end", "sNaKEr.end", "snakeSnakeCase.end", "snakeSnakECase.end",
"snakeSnakECase.end", "ssRRss.end", "ssRrrr.end", "thisIsSomeCamelCase.end",
"this.Text.end", "finalCount.end", "bobDylanUsa.end", "mikhailGorbachevUssr.end",
"helpfulStackOverflowPeople.end", "imATallDrinkOfWater.end",
"icuDays.end", "sexCode.end", "maxOfMld.end", "age.Group.end",
NA, ".end", "SNaKEr.end", "SnakeSnakeCase.end", "SnakeSnakECase.end",
"SnakeSnakECase.end", "SsRRss.end", "SsRrrr.end", "ThisIsSomeCamelCase.end",
"This.Text.end", "FinalCount.end", "BobDylanUsa.end", "MikhailGorbachevUssr.end",
"HelpfulStackOverflowPeople.end", "ImATallDrinkOfWater.end",
"IcuDays.end", "SexCode.end", "MaxOfMld.end", "Age.Group.end",
NA, ".end", "S_NA_K_ER.end", "SNAKE_SNAKE_CASE.end", "SNAKE_SNAK_E_CASE.end",
"SNAKE_SNAK_E_CASE.end", "SS_R_RSS.end", "SS_RRRR.end", "THIS_IS_SOME_CAMEL_CASE.end",
"THIS.TEXT.end", "FINAL_COUNT.end", "BOB_DYLAN_USA.end", "MIKHAIL_GORBACHEV_USSR.end",
"HELPFUL_STACK_OVERFLOW_PEOPLE.end", "IM_A_TALL_DRINK_OF_WATER.end",
"ICU_DAYS.end", "SEX_CODE.end", "MAX_OF_MLD.end", "AGE.GROUP.end",
NA, "start.", "start.s_na_k_er", "start.SNAKE_SNAKE_CASE", "start.snake_Snak_E_Case",
"start.SNAKE_snak_E_case", "start.ss_R_Rss", "start.ss_RRRR",
"start.this_Is_Some_Camel_Case", "start.this.text", "start.final_count",
"start.Bob_Dylan_USA", "start.Mikhail_Gorbachev_USSR", "start.Helpful_Stack_Overflow_People",
"start.Im_A_Tall_Drink_Of_Water", "start.ICU_Days", "start.Sex_Code",
"start.MAX_of_MLD", "start.Age.Group", NA, "start.", "start.s_na_k_er",
"start.snake_snake_case", "start.snake_snak_e_case", "start.snake_snak_e_case",
"start.ss_r_rss", "start.ss_rrrr", "start.this_is_some_camel_case",
"start.this.text", "start.final_count", "start.bob_dylan_usa",
"start.mikhail_gorbachev_ussr", "start.helpful_stack_overflow_people",
"start.im_a_tall_drink_of_water", "start.icu_days", "start.sex_code",
"start.max_of_mld", "start.age.group", NA, "start.", "start.sNaKEr",
"start.snakeSnakeCase", "start.snakeSnakECase", "start.snakeSnakECase",
"start.ssRRss", "start.ssRrrr", "start.thisIsSomeCamelCase",
"start.this.Text", "start.finalCount", "start.bobDylanUsa", "start.mikhailGorbachevUssr",
"start.helpfulStackOverflowPeople", "start.imATallDrinkOfWater",
"start.icuDays", "start.sexCode", "start.maxOfMld", "start.age.Group",
NA, "start.", "start.SNaKEr", "start.SnakeSnakeCase", "start.SnakeSnakECase",
"start.SnakeSnakECase", "start.SsRRss", "start.SsRrrr", "start.ThisIsSomeCamelCase",
"start.This.Text", "start.FinalCount", "start.BobDylanUsa", "start.MikhailGorbachevUssr",
"start.HelpfulStackOverflowPeople", "start.ImATallDrinkOfWater",
"start.IcuDays", "start.SexCode", "start.MaxOfMld", "start.Age.Group",
NA, "start.", "start.S_NA_K_ER", "start.SNAKE_SNAKE_CASE", "start.SNAKE_SNAK_E_CASE",
"start.SNAKE_SNAK_E_CASE", "start.SS_R_RSS", "start.SS_RRRR",
"start.THIS_IS_SOME_CAMEL_CASE", "start.THIS.TEXT", "start.FINAL_COUNT",
"start.BOB_DYLAN_USA", "start.MIKHAIL_GORBACHEV_USSR", "start.HELPFUL_STACK_OVERFLOW_PEOPLE",
"start.IM_A_TALL_DRINK_OF_WATER", "start.ICU_DAYS", "start.SEX_CODE",
"start.MAX_OF_MLD", "start.AGE.GROUP", NA, "start..end", "start.s_na_k_er.end",
"start.SNAKE_SNAKE_CASE.end", "start.snake_Snak_E_Case.end",
"start.SNAKE_snak_E_case.end", "start.ss_R_Rss.end", "start.ss_RRRR.end",
"start.this_Is_Some_Camel_Case.end", "start.this.text.end",
"start.final_count.end", "start.Bob_Dylan_USA.end", "start.Mikhail_Gorbachev_USSR.end",
"start.Helpful_Stack_Overflow_People.end", "start.Im_A_Tall_Drink_Of_Water.end",
"start.ICU_Days.end", "start.Sex_Code.end", "start.MAX_of_MLD.end",
"start.Age.Group.end", NA, "start..end", "start.s_na_k_er.end",
"start.snake_snake_case.end", "start.snake_snak_e_case.end",
"start.snake_snak_e_case.end", "start.ss_r_rss.end", "start.ss_rrrr.end",
"start.this_is_some_camel_case.end", "start.this.text.end",
"start.final_count.end", "start.bob_dylan_usa.end", "start.mikhail_gorbachev_ussr.end",
"start.helpful_stack_overflow_people.end", "start.im_a_tall_drink_of_water.end",
"start.icu_days.end", "start.sex_code.end", "start.max_of_mld.end",
"start.age.group.end", NA, "start..end", "start.sNaKEr.end",
"start.snakeSnakeCase.end", "start.snakeSnakECase.end", "start.snakeSnakECase.end",
"start.ssRRss.end", "start.ssRrrr.end", "start.thisIsSomeCamelCase.end",
"start.this.Text.end", "start.finalCount.end", "start.bobDylanUsa.end",
"start.mikhailGorbachevUssr.end", "start.helpfulStackOverflowPeople.end",
"start.imATallDrinkOfWater.end", "start.icuDays.end", "start.sexCode.end",
"start.maxOfMld.end", "start.age.Group.end", NA, "start..end",
"start.SNaKEr.end", "start.SnakeSnakeCase.end", "start.SnakeSnakECase.end",
"start.SnakeSnakECase.end", "start.SsRRss.end", "start.SsRrrr.end",
"start.ThisIsSomeCamelCase.end", "start.This.Text.end", "start.FinalCount.end",
"start.BobDylanUsa.end", "start.MikhailGorbachevUssr.end", "start.HelpfulStackOverflowPeople.end",
"start.ImATallDrinkOfWater.end", "start.IcuDays.end", "start.SexCode.end",
"start.MaxOfMld.end", "start.Age.Group.end", NA, "start..end",
"start.S_NA_K_ER.end", "start.SNAKE_SNAKE_CASE.end", "start.SNAKE_SNAK_E_CASE.end",
"start.SNAKE_SNAK_E_CASE.end", "start.SS_R_RSS.end", "start.SS_RRRR.end",
"start.THIS_IS_SOME_CAMEL_CASE.end", "start.THIS.TEXT.end",
"start.FINAL_COUNT.end", "start.BOB_DYLAN_USA.end", "start.MIKHAIL_GORBACHEV_USSR.end",
"start.HELPFUL_STACK_OVERFLOW_PEOPLE.end", "start.IM_A_TALL_DRINK_OF_WATER.end",
"start.ICU_DAYS.end", "start.SEX_CODE.end", "start.MAX_OF_MLD.end",
"start.AGE.GROUP.end"))
}
)
test_that("sep_out", {
paste_along <- function(x, along = "_") {
if (length(x) <= 1L) return(x)
if (length(along) == 1L) return(paste0(x, collapse = along))
along <- c(along, rep_len(along[length(along)], max(length(x) - length(along), 0L)))
paste0(paste0(x[seq_len(length(x) - 1)], along[seq_len(length(x) - 1)],
collapse = ""), x[length(x)])
}
expect_equal(to_any_case("a", sep_out = "-"), "a")
expect_equal(to_any_case(""), "")
expect_equal(to_any_case("a"), "a")
expect_equal(to_any_case(c("bla_bla_bla"), sep_out = c("-", "_")), "bla-bla_bla")
expect_equal(to_any_case(c("2018_01_01_bla_bla_bla"), sep_out = c("-", "_")), "2018-01_01_bla_bla_bla")
expect_equal(to_any_case(c("2018_01_01_bla_bla_bla"), sep_out = "-"), "2018-01-01-bla-bla-bla")
expect_equal(to_any_case(c("2018_01_01_bla_bla"), sep_out = c("-", "-", "_", "_", "_", "_", "_")), "2018-01-01_bla_bla")
expect_equal(to_any_case(character(0), sep_out = c("_", "_")), character(0))
})
test_that("random case", {
expect_equal(
{suppressWarnings(RNGversion("3.1")); set.seed(123); to_any_case("almost RANDOM", case = "random")},
"AlMosT raNdOm"
)
})
test_that("title case", {
expect_equal(
to_any_case(c("on_andOn", "AndON", " and on", "and so on", "seems like it works", "also abbreviations ETC"), case = "title", abbreviations = "ETC"),
c("On and on", "And on", "And on", "And so on", "Seems Like it Works", "Also Abbreviations ETC")
)
})
test_that("case none", {
expect_equal(
to_any_case(c("blabla", "blablub", "blaBlub"),case = "none", transliterations = c(blab = "blub")),
c("blubla", "blublub", "blaBlub")
)
})
test_that("special_input", {
expect_identical(to_any_case(NA_character_), NA_character_)
expect_equal(to_any_case(character(0)), character(0))
})
test_that("special_input_2", {
skip_if(getRversion() < 3.4)
# atomics
expect_equal(to_any_case(character()), character())
expect_error(to_any_case(logical()), "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(integer()), "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(double()), "argument is not a character vector", fixed = TRUE)
# data structures
expect_error(to_any_case(data.frame()), "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(list()) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(matrix()) , "argument is not a character vector", fixed = TRUE)
# special input or wrong type
expect_error(to_any_case(NA) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(NA_integer_) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(NA_real_) , "argument is not a character vector", fixed = TRUE)
expect_equal(to_any_case(NA_character_) , NA_character_)
expect_error(to_any_case(TRUE) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(1.0) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(1L) , "argument is not a character vector", fixed = TRUE)
expect_equal(to_any_case(c("a", 1L)) , c("a", "1"))
expect_error(to_any_case(NULL) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(NaN) , "argument is not a character vector", fixed = TRUE)
expect_error(to_any_case(Inf) , "argument is not a character vector", fixed = TRUE)
})
test_that("abbreviations", {
expect_equal(to_any_case("IDENTICALid3", abbreviations = "iD3"), "identical_id3")
})
test_that("parsing_options", {
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = 1),
"RRR_Studio_S_Studio_Studio"
)
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = -1),
"RRR_Studio_S_Studio_Studio"
)
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = 2),
"RRRS_tudio_SS_tudio_Studio"
)
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = -2),
"RRRS_tudio_SS_tudio_Studio"
)
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = 3),
"RRRStudio_SStudio_Studio"
)
expect_equal(to_any_case("RRRStudioSStudioStudio", case = "parsed", parsing_option = -3),
"RRRStudio_SStudio_Studio"
)
})
test_that("individual abbreviations", {
expect_equal(
to_any_case("NBAGame", abbreviations = "NBA", case = "mixed"),
"NBA_Game"
)
expect_equal(
to_any_case("NBAGame", abbreviations = "NBa", case = "mixed"),
"NBa_Game"
)
expect_equal(
to_any_case("NBAGame", abbreviations = "baa", case = "mixed"),
"Nba_Game"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVP", case = "mixed"),
"Game_MVP"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVp", case = "mixed"),
"Game_MVp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "mvp", case = "mixed"),
"Game_mvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "mvp", case = "upper_camel"),
"GameMvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVP", case = "upper_camel"),
"GameMVP"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVp", case = "upper_camel"),
"GameMVp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "mvp", case = "title"),
"Game Mvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVP", case = "title"),
"Game MVP"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVp", case = "title"),
"Game MVp"
)
expect_equal(
to_any_case("UserID", abbreviations = "id", case = "title"),
"User Id"
)
expect_equal(
to_any_case("UserID", abbreviations = "ID", case = "title"),
"User ID"
)
expect_equal(
to_any_case("UserID", abbreviations = "id", case = "upper_camel"),
"UserId"
)
expect_equal(
to_any_case("UserID", abbreviations = "ID", case = "upper_camel"),
"UserID"
)
expect_equal(
to_any_case("UserID", abbreviations = "id", case = "mixed"),
"User_id"
)
expect_equal(
to_any_case("UserID", abbreviations = "ID", case= "mixed"),
"User_ID"
)
expect_equal(
to_any_case("UserID", abbreviations = "Id", case = "mixed"),
"User_Id"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "mvp", case = "lower_camel"),
"gameMvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVP", case = "lower_camel"),
"gameMVP"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "MVp", case = "lower_camel"),
"gameMVp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "GAME", case = "lower_camel"),
"gameMvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "game", case = "lower_camel"),
"gameMvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "gGame", case = "lower_camel"),
"gameMvp"
)
expect_equal(
to_any_case("GameMVP", abbreviations = "Game", case = "lower_camel"),
"gameMvp"
)
expect_equal(
to_any_case("nba_finals_mvp", abbreviations = c("nba", "MVP"), case = "upper_camel"),
"NbaFinalsMVP"
)
expect_equal(
to_any_case("nba_finals_mvp", abbreviations = c("nba", "MVp"), case = "upper_camel"),
"NbaFinalsMVp"
)
})
test_that("parsing_option 2", {
expect_equal(to_any_case("blaBLA", abbreviations = "BLA", parsing_option = 2),
"bla_bla")
})
test_that("parsing_option 3", {
expect_equal(to_any_case("blaBLA", abbreviations = "BLA", parsing_option = 3),
"bla_bla")
}) snakecase/tests/testthat/test-to_parsed_case.R 0000644 0001762 0000144 00000002205 13420607650 021266 0 ustar ligges users context("to_parsed_case")
test_that("examples", {
expect_equal(to_parsed_case(cases[["examples"]]),
cases[["parsed_case"]])}
)
test_that("rules",{
examples <- cases[["examples"]]
# note that to parsed case has a little bit different rules than the other converters
expect_equal(to_parsed_case(to_parsed_case(examples)),
to_parsed_case(examples))
expect_equal(to_parsed_case(to_snake_case(examples)),
to_snake_case(examples))
#expect_equal(to_parsed_case(to_small_camel_case(examples)),
# to_small_camel_case(examples))
#
#expect_equal(to_parsed_case(to_big_camel_case(examples)),
# to_big_camel_case(examples))
expect_equal(to_parsed_case(to_screaming_snake_case(examples)),
to_screaming_snake_case(examples))
})
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_parsed_case(labs),
structure(c("abc_DEF", "bbcc_EE", "Te_E_St_it"), .Names = c("a",
"b", "c"))
)
}) snakecase/tests/testthat/test-to_lower_upper_case.R 0000644 0001762 0000144 00000000713 13420607650 022355 0 ustar ligges users context("to_upper_lower_case")
test_that("random stuff", {
expect_equal(to_lower_upper_case("RStudioRRRStudio"),
"rSTUDIOrrrSTUDIO")
}
)
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_lower_upper_case(labs),
structure(c("abcDEF", "bbccEE", "teEstIT"), .Names = c("a", "b",
"c"))
)
}) snakecase/tests/testthat/test-to_upper_lower_case.R 0000644 0001762 0000144 00000001121 13420607650 022347 0 ustar ligges users context("to_upper_lower_case")
test_that("random stuff", {
expect_equal(to_upper_lower_case("RStudioRRRStudio"),
"RstudioRRRstudio")
expect_equal(to_upper_lower_case(c("R.aStudio", NA, NA, NA, NA)),
c("RaSTUDIO", NA, NA, NA, NA))
}
)
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_any_case(labs, case = "upper_lower"),
structure(c("ABCdef", "BBCCee", "TEeSTit"), .Names = c("a", "b",
"c"))
)
}) snakecase/tests/testthat/test-to_random_case.R 0000644 0001762 0000144 00000000245 13467441350 021276 0 ustar ligges users test_that("random_case", {
expect_equal(
{suppressWarnings(RNGversion("3.1")); set.seed(123); to_random_case("almost RANDOM")},
"AlMosT raNdOm"
)
}) snakecase/tests/testthat/test-to_sentence_case.R 0000644 0001762 0000144 00000001310 13420607650 021610 0 ustar ligges users context("to_sentence_case")
test_that("basic_example",{
expect_equal(
to_sentence_case("bla bla_bal"),
"Bla bla bal")
expect_equal(to_sentence_case("the_boy_likes_snake_case",
transliterations = c("boy" = "baby",
"snake" = "screaming__snake"),
sep_out = " "),
"The baby likes screaming snake case")
expect_equal(to_sentence_case("the_boy_likes_snake_case",
transliterations = c("boy" = "baby",
"snake" = "screaming__snake")),
"The baby likes screaming snake case")
}) snakecase/tests/testthat/helper-examples.R 0000644 0001762 0000144 00000023656 13420607650 020446 0 ustar ligges users # cases for examples
cases <-
tibble::tribble(
~nr, ~ examples ,~parsed_case , ~snake_case , ~small_camel_case , ~big_camel_case , ~screaming_snake_case ,
#--|-----------------------------,--------------------------------|------------------------------|------------------------------|------------------------------|-----------------------|
1 , NA , NA , NA , NA , NA , NA,
2 , "snake_case" , "snake_case" , "snake_case" , "snakeCase" , "SnakeCase" , "SNAKE_CASE",
3 , "snakeCase" , "snake_Case" , "snake_case" , "snakeCase" , "SnakeCase" , "SNAKE_CASE",
4 , "SnakeCase" , "Snake_Case" , "snake_case" , "snakeCase" , "SnakeCase" , "SNAKE_CASE",
5 , "_" , "" , "" , "" , "" , "",
6 , "snake_Case" , "snake_Case" , "snake_case" , "snakeCase" , "SnakeCase" , "SNAKE_CASE",
7 , "_" , "" , "" , "" , "" , "",
8 , "SNake" , "S_Nake" , "s_nake" , "sNake" , "SNake" , "S_NAKE",
9 , "Snake" , "Snake" , "snake" , "snake" , "Snake" , "SNAKE",
10 , "s_nake" , "s_nake" , "s_nake" , "sNake" , "SNake" , "S_NAKE",
11 , "sn_ake" , "sn_ake" , "sn_ake" , "snAke" , "SnAke" , "SN_AKE",
12 , "_" , "" , "" , "" , "" , "",
13 , "SNaKE" , "S_Na_KE" , "s_na_ke" , "sNaKe" , "SNaKe" , "S_NA_KE",
14 , "SNaKEr" , "S_Na_K_Er" , "s_na_k_er" , "sNaKEr" , "SNaKEr" , "S_NA_K_ER",
15 , "s_na_k_er" , "s_na_k_er" , "s_na_k_er" , "sNaKEr" , "SNaKEr" , "S_NA_K_ER",
16 , "_" , "" , "" , "" , "" , "",
17 , "SNAKE SNAKE CASE" , "SNAKE_SNAKE_CASE" , "snake_snake_case" , "snakeSnakeCase" , "SnakeSnakeCase" , "SNAKE_SNAKE_CASE",
18 , "_" , "" , "" , "" , "" , "",
19 , "snakeSnakECase" , "snake_Snak_E_Case" , "snake_snak_e_case" , "snakeSnakECase" , "SnakeSnakECase" , "SNAKE_SNAK_E_CASE",
20 , "SNAKE snakE_case" , "SNAKE_snak_E_case" , "snake_snak_e_case" , "snakeSnakECase" , "SnakeSnakECase" , "SNAKE_SNAK_E_CASE",
21 , "_" , "" , "" , "" , "" , "",
22 , "ssRRss" , "ss_R_Rss" , "ss_r_rss" , "ssRRss" , "SsRRss" , "SS_R_RSS",
23 , "ssRRRR" , "ss_RRRR" , "ss_rrrr" , "ssRrrr" , "SsRrrr" , "SS_RRRR",
24 , "thisIsSomeCamelCase" , "this_Is_Some_Camel_Case" , "this_is_some_camel_case" , "thisIsSomeCamelCase" , "ThisIsSomeCamelCase" , "THIS_IS_SOME_CAMEL_CASE",
25 , "this.text" , "this_text" , "this_text" , "thisText" , "ThisText" , "THIS_TEXT",
26 , "next.text" , "next_text" , "next_text" , "nextText" , "NextText" , "NEXT_TEXT",
27 , "zip code" , "zip_code" , "zip_code" , "zipCode" , "ZipCode" , "ZIP_CODE",
28 , "state" , "state" , "state" , "state" , "State" , "STATE",
29 , "final count" , "final_count" , "final_count" , "finalCount" , "FinalCount" , "FINAL_COUNT",
30 , "BobDylanUSA" , "Bob_Dylan_USA" , "bob_dylan_usa" , "bobDylanUsa" , "BobDylanUsa" , "BOB_DYLAN_USA",
31 , "MikhailGorbachevUSSR" , "Mikhail_Gorbachev_USSR" , "mikhail_gorbachev_ussr" , "mikhailGorbachevUssr" , "MikhailGorbachevUssr" , "MIKHAIL_GORBACHEV_USSR",
32 , "HelpfulStackOverflowPeople", "Helpful_Stack_Overflow_People", "helpful_stack_overflow_people", "helpfulStackOverflowPeople" , "HelpfulStackOverflowPeople" , "HELPFUL_STACK_OVERFLOW_PEOPLE",
33 , "IAmATallDrinkOfWater" , "I_Am_A_Tall_Drink_Of_Water" , "i_am_a_tall_drink_of_water" , "iAmATallDrinkOfWater" , "IAmATallDrinkOfWater" , "I_AM_A_TALL_DRINK_OF_WATER",
34 , "ICUDays" , "ICU_Days" , "icu_days" , "icuDays" , "IcuDays" , "ICU_DAYS",
35 , "SexCode" , "Sex_Code" , "sex_code" , "sexCode" , "SexCode" , "SEX_CODE",
36 , "MAX_of_MLD" , "MAX_of_MLD" , "max_of_mld" , "maxOfMld" , "MaxOfMld" , "MAX_OF_MLD",
37 , "Age.Group" , "Age_Group" , "age_group" , "ageGroup" , "AgeGroup" , "AGE_GROUP",
38 , "ThisText" , "This_Text" , "this_text" , "thisText" , "ThisText" , "THIS_TEXT",
39 , "NextText" , "Next_Text" , "next_text" , "nextText" , "NextText" , "NEXT_TEXT",
40 , "test_123_ 1 1" , "test_123_1_1" , "test_123_1_1" , "test123_1_1" , "Test123_1_1" , "TEST_123_1_1"
)
# dat for arguments of to_any_case(). test non NULL arguments via dat.
# test other three special case via specific examples
string <- c(NA, "_", "s_na_k_er", "SNAKE SNAKE CASE", "snakeSnakECase",
"SNAKE snakE_case", "ssRRss", "ssRRRR", "thisIsSomeCamelCase",
"this.text", "final count", "BobDylanUSA", "MikhailGorbachevUSSR",
"HelpfulStackOverflowPeople", "ImATallDrinkOfWater", "ICUDays", "SexCode",
"MAX_of_MLD", "Age.Group")
case <- c("parsed", "snake", "small_camel", "big_camel", "screaming_snake")
prefix <- c("", "start.")
postfix <- c("", ".end")
transliterations <- c("german", "Latin-ASCII")
dat <- expand.grid(string = string,
case = case,
postfix = postfix,
prefix = prefix,
transliterations = transliterations,
stringsAsFactors = FALSE)
# code to generate new results.
# purrrlyr::invoke_rows(snakecase::to_any_case, dat,
# preprocess = NULL,
# postprocess = NULL,
# .collate = "cols",
# .to = "output") %>% .$output %>% dput()
# Some Benchmarks:
# devtools::install_github("Tazinho/snakecase", force = TRUE)
# library(snakecase)
#
# string_gen <- function(times){paste0("str", 1:times)}
# other_gen <- function(times){paste0("other", 1:times)}
#
# str10 <- string_gen(10)
# str1000 <- string_gen(1000)
# oth10 <- other_gen(10)
# oth1000 <- other_gen(1000)
#
# microbenchmark::microbenchmark(
# to_any_case(string = str10, case = "snake", preprocess = oth10),
# to_any_case(string = str1000, case = "snake", preprocess = oth1000)
# )
#
# microbenchmark::microbenchmark(
# to_any_case(string = str10, case = "snake", postprocess = oth10),
# to_any_case(string = str1000, case = "snake", postprocess = oth1000)
# )
#
# microbenchmark::microbenchmark(
# to_any_case(string = str10, case = "snake", prefix = oth10),
# to_any_case(string = str1000, case = "snake", prefix = oth1000)
# )
#
# microbenchmark::microbenchmark(
# to_any_case(string = str10, case = "snake" , postfix = oth10),
# to_any_case(string = str1000, case = "snake", postfix = oth1000)
# )
#
# microbenchmark::microbenchmark(
# to_any_case(string = str10, case = "snake" , protect = oth10),
# to_any_case(string = str1000, case = "snake", protect = oth1000)
# ) snakecase/tests/testthat/test-to_upper_camel_case.R 0000644 0001762 0000144 00000004222 13470313655 022311 0 ustar ligges users context("to_upper_camel_case")
test_that("examples", {
expect_equal(to_upper_camel_case(cases[["examples"]]),
cases[["big_camel_case"]])}
)
test_that("rules",{
examples <- cases[["examples"]]
expect_equal(to_upper_camel_case(to_snake_case(examples)),
to_upper_camel_case(examples)
)
expect_equal(to_upper_camel_case(to_lower_camel_case(examples)),
to_upper_camel_case(examples)
)
expect_equal(to_upper_camel_case(to_upper_camel_case(examples)),
to_upper_camel_case(examples)
)
expect_equal(to_upper_camel_case(to_screaming_snake_case(examples)),
to_upper_camel_case(examples)
)
expect_equal(to_upper_camel_case(to_parsed_case(examples)),
to_upper_camel_case(examples)
)
})
test_that("preserve-names-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(to_upper_camel_case(labs),
structure(c("AbcDef", "BbccEe", "TeEStIt"),
.Names = c("a", "b", "c")))
})
test_that("parsing_options",{
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = 1, numerals = "asis", sep_in = NULL),
"LookAfterThe-HyphenAndThe.Dot")
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = -1, numerals = "asis", sep_in = NULL),
"LookAfterThe-hyphenAndThe.dot")
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = 2, numerals = "asis", sep_in = NULL),
"LookAfterThe-HyphenAndThe.Dot")
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = -2, numerals = "asis", sep_in = NULL),
"LookAfterThe-hyphenAndThe.dot")
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = 3, numerals = "asis", sep_in = NULL),
"LookAfterThe-HyphenAndThe.Dot")
expect_equal(to_upper_camel_case("look_AfterThe-hyphen andThe.dot", parsing_option = -3, numerals = "asis", sep_in = NULL),
"LookAfterThe-hyphenAndThe.dot")
}) snakecase/tests/testthat/test-to_swap_case.R 0000644 0001762 0000144 00000000226 13420607650 020763 0 ustar ligges users context("to_swap_case")
test_that("minimal test",{
expect_equal(
to_swap_case(c("abCD", "RStudio")),
c("ABcd", "rsTUDIO")
)
}) snakecase/tests/testthat/test-to_mixed_case.R 0000644 0001762 0000144 00000000706 13420607650 021122 0 ustar ligges users context("to_mixed_case")
test_that("random stuff", {
expect_equal(to_mixed_case("RStudioRRRStudio"),
"R_Studio_Rrr_Studio")
}
)
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_mixed_case(labs),
structure(c("abc_Def", "bbcc_Ee", "Te_E_St_it"), .Names = c("a",
"b", "c"))
)
}) snakecase/tests/testthat/test-to_snake_case.R 0000644 0001762 0000144 00000002045 13420607650 021113 0 ustar ligges users context("to_snake_case")
test_that("examples", {
expect_equal(to_snake_case(cases[["examples"]]),
cases[["snake_case"]])}
)
test_that("rules",{
examples <- cases[["examples"]]
expect_equal(to_snake_case(to_snake_case(examples)),
to_snake_case(examples)
)
expect_equal(to_snake_case(to_lower_camel_case(examples)),
to_snake_case(examples)
)
expect_equal(to_snake_case(to_upper_camel_case(examples)),
to_snake_case(examples)
)
expect_equal(to_snake_case(to_screaming_snake_case(examples)),
to_snake_case(examples)
)
expect_equal(to_snake_case(to_parsed_case(examples)),
to_snake_case(examples)
)
})
test_that("preserve-name-attribute",{
labs <- c(a = "abcDEF", b = "bbccEE", c = "TeESt it")
expect_equal(
to_snake_case(labs),
structure(c("abc_def", "bbcc_ee", "te_e_st_it"), .Names = c("a",
"b", "c"))
)
}) snakecase/NAMESPACE 0000644 0001762 0000144 00000000577 13472267031 013444 0 ustar ligges users # Generated by roxygen2: do not edit by hand
export(to_any_case)
export(to_lower_camel_case)
export(to_lower_upper_case)
export(to_mixed_case)
export(to_parsed_case)
export(to_random_case)
export(to_screaming_snake_case)
export(to_sentence_case)
export(to_snake_case)
export(to_swap_case)
export(to_title_case)
export(to_upper_camel_case)
export(to_upper_lower_case)
snakecase/NEWS.md 0000644 0001762 0000144 00000042300 13472270604 013311 0 ustar ligges users # snakecase 0.11.0 (25.05.19)
**Changes in 0.10.0 and 0.10.0.9000**
New functionality:
* **abbreviations**: Abbreviations are now ...
* ... matched case-insensitive inside of groups of connected lower/upper case sequences.
* ... consistently formatted according to the supplied case.
* ... formatted exactly as supplied for the cases title, mixed, lower and upper camel.
* ... protected from the parsing. This means that
* special characters in abbreviations don't need to be taken care of anymore. The formatting of digits or special characters like hyphens, colons etc. will be formatted as specified.
* **parsing_option**:
* new parsing option 3 parses "SOmeNIceSTUFf".
* parsing options starting with a minus (-1, -2, -3) interprete non-alphanumeric characters as word boundaries. E.g. "This.text" will stay "This.text" in upper camel case.
* **cases**
* **title**: New case which should be especially useful for automatic generation of proper labels within graphics or business reports. Builds up on sentence case which is wrapped within `tools::toTitleCase()`.
* **random**: New case, which will randomly convert letters into upper or lower case.
* **numerals**: new alignment option `"tight"` which allows to suppress all underscores between numerals and letters.
* **sep_out**: `sep_out` gets proper vectorization. In case of `length(sep_out) > 1` differing substrings are connected by the (possibly) differing elements of `sep_out`. Therefore, `sep_out` gets accordingly shortened or the last element of `sep_out` gets recycled to match the number of needed separators for each element of `string`.
* **UTF8 Conversion**: Input is now always converted to UTF-8 and returned as UTF8. Also the `transliterations` argument is now aware of non-UTF8 encoded input.
Infrastructure:
* **CII best practices badge**: Achieved the criteria for the best practices badge. Current status is under https://bestpractices.coreinfrastructure.org/de/projects/2475
* **R Version**: Increase from 3.1 to 3.2 regarding the usage of `tools::toTitleCase()` inside `to_title_case()`.
* **Vignettes**: The blog article "Introducing the snakecase package" was added as a vignette.
* **Documentation**: The readme, the examples and the function documentation were updated according to the new functionality.
* **Resolve CRAN notes**:
* **Tests**: Skip `to_any_case()` tests (janitor-pkg-tests, transliterations and complex strings) when platform charset is not UTF-8 to resolve CRAN notification regarding character encoding.
* **Vignettes**: Build the package with new version of knitr to resolve CRAN notification regarding vignette encoding.
# snakecase 0.10.0.9000
* **cases**: Title case now builds up on sentence case (instead of parsed_case).
* **abbreviations**: Abbreviations are now
* matched case-insensitive
* formatted as they are supplied for title-, upper-camel-, lower-camel- and mixed case. Apart of that abbreviations are still formatted according to the specified case.
* protected from the parsing. This means that
* special characters in abbreviations don't need to be excluded via a regex in the `sep_in` parameter
* the formatting of digits or special characters like hyphens, colons etc. will be formatted as specified.
* **parsing_option**:
* new parsing option 3 implemented which parses "SOmeNIceSTUFf".
* each parsing option can now be prefixed by a minus (-1, -2, -3). In this way
# snakecase 0.10.0 (16.05.19)
* CRAN release
# snakecase 0.9.2.9002
* **numerals**: new alignment option `"tight"` which allows to suppress all underscores between numerals and letters.
* **improved speed**: time of internal parsing could be reduced about a factor of ten, due to some `vapply()` replacements.
* **UTF8 Conversion**: Input is now always converted to UTF-8 and returned as UTF8. Also the `transliterations` argument is now aware of non-UTF8 encoded input.
* **Improved vecorisation of `sep_out`**: `sep_out` now behaves better for vector input (length > 1). Instead of returning different strings, the return is now one string, which uses separators according to the supplied order. When `length(sep_out) > 1`, the last element of `sep_out` gets recycled.
* **random_case**: added `to_random_case()`, which will randomly convert letters into upper or lower case.
* **title_case**: added `to_title_case()`, which is basically `to_parsed_case()` with `sep_out = " "` wrapped within `tools::toTitleCase()` and should be especially useful for proper labels within graphics or business reports.
* increase R Version dependency from 3.1 up to 3.2 regarding the usage of `tools::toTitleCase()`.
* skip `to_any_case()` tests (janitor-pkg-tests, transliterations and complex strings) when platform charset is not UTF-8.
# snakecase 0.9.2
* **cases**: added `to_sentence_case()` (same as snake, but first letter is uppercase and default sep_out is space).
* **numerals**: added `numerals` argument to all caseconverters including `to_any_case()` to format the alignment of digits (`middle`, `left`,`right`, `asis`). Therefore `parsing_option` nr 4 might be removed in later releases, as it is the same as `parsing_option = 1` and `numerals = "asis"`.
* **transliterations**: When named character elements are supplied as part of `transliterations`, anything that matches the name is replaced by the corresponding value.
* attributes are now preserved (not only names as before)
# snakecase 0.9.1
* CRAN release
* Change default `sep_in` from `NULL` to `"[^[:alnum:]]"`. This will make it easier for beginners and in general also faster to modify cases from names like `names(iris)`. Updated the regarding sections in the vignette and readme.
# snakecase 0.9.0
* CRAN release
* Changes since last update:
* parsing_options:
* old parsing_options 3 and 4 are replaced now by new
* parsing_option 3, which suppresses case conversion around alpha numerics
* parsing_option 4, which introduces less formatting of numerals in the output,
and leaves them very close to the way that they appeared in the input strings.
* abbreviations:
* they work now more consistent with cases like lower- and upper camel case
* new converters:
* `to_swap_case()` is new. Within `to_any_case()` this conversion can be called also via `case = "flip"`.
* removed deprecated arguments
* `replace_special_characters`, which is now called `transliterations`
* `preprocess`, which is now called `sep_in`
* `postprocess`, which is now called `sep_out`
* removed dependencies:
* purrr and magrittr are not longer dependencies
* stringr is the only dependency now (including stringi of course).
# snakecase 0.8.4
* Introduced `to_swap_case()`, which is also available in `to_any_case()` via
`case = "swap"` or `case = "flip"`
# snakecase 0.8.3.1
* abbreviations work now also in conversions to lower- and upper camel case.
# snakecase 0.8.3
* replaced `parsing_option`s 3 and 4 with 5 and 6.
* removed __purrr__ dependency
* removed __magrittr__ dependency
# snakecase 0.8.2.9002
* remove `replace_special_characters`, `preprocess` and `postprocess`.
# snakecase 0.8.2.9001
* added parsing option 6, which doesn't surround digits with separators.
# snakecase 0.8.1
* CRAN releases
# snakecase 0.8.0.9000
* some breaking changes:
* reordering of the arguments of all `to_xxx_case()` functions
* renaming `preprocess` to `sep_in`, `postprocess` to `sep_out`,
`replace_special_characters` to `transliterations`.
# snakecase 0.7.1
* CRAN update
* for changes see V 0.7.0
* additionally fixed obvious bug and forwarded to_xxx_case args to to_any_case
# snakecase 0.7.0
* changes since last CRAN submission include:
* to_xxx_case shortcuts are now exact wrappers around to_any_case
* `process` is deprecated after changing implementation and setting a reasonable default.
* added `abbreviations` argument to `any_case()`
* case none is now a lot more general for formatting
* added `abbreviation` specific behaviour for mixed case
* new parsing_option 5, which suppresses conversion after ., @, etc
* renaming of:
* to_small / to_big_camel_case have been renamed to to_lower / to_upper_camel_case. The old names are and will still be supported in to_any_case
* `parsingoption` to `parsing_option`
* introduced rule that parsing_option <= 0 suppresses parsing from now on
* lots of additional tests and smaller bugfixes
* several documentation updates including help, examples, readme and vignette
# snakecase 0.6.2.9000
* all to_xxx_case functions are now exact wrappers of to_any_case
* to_small / to_big_camel_case have been renamed to to_lower / to_upper_camel_case
* minimal vignette update
# snakecase 0.6.1.9000
* more consistency for case none
* bugfix for parsing option 5
# snakecase 0.6.0.9000
* overhaul readme
* renamed `parsingoption` argument to `parsing_option`
* `process` argument: changed implementation in `to_any_case`, set a reasonable default, implemented the behaviour also in to_xxx shortcut functions, deprecated `process` argument
* make modifications to case none, which allows now more parsing options
# snakecase 0.5.4.9000
* added special behaviour for abbreviations within "mixed_case"
# snakecase 0.5.3.9000
* added abbreviations argument for better mixed case handling
# snakecase 0.5.2.9000
* improve consistency with stringr pkg regarding special input handling
`if(identical(stringr::str_length(string), integer())){return(character())}`
# snakecase 0.5.1
* Changes since last update:
* `to_any_case()` and shortcuts (`to_xxx_case()` functions) preserve name attribute now
* R dependency lowered to 3.1
# snakecase 0.5.0.9001
* `to_any_case()` and the other converter function now preserve the names attribute. (Thanks to @strengejacke)
# snakecase 0.5.0
* CRAN update
* Changes since last CRAN submission include:
* string transliteration via updated `replace_special_character` argument
* some new cases: "none", "mixed", "upper_lower", "lower_upper"
* aliases: "all_caps", "lower_camel", "upper_camel"
* different parsing options
* several bugfixes
* improved internal testing
* internal modularisation
# snakecase 0.4.0.9016
* `case == "none"` works now with `preprocess`.
# snakecase 0.4.0.9015
* fixed bug so that `case = upper_lower` no also works for `NA`'s.
# snakecase 0.4.0.9014
* added shortcutfunctions `to_mixed_case()`, `to_lower_upper_case()` and `to_upper_lower_case()`.
# snakecase 0.4.0.9013
Implemented two further parsing options:
* 3: parses the first UPPER letter group like parsing option 2 and the rest like option 1
* 4: parses the first UPPERlowercase letter group like parsingoption 1 and the rest like option 2
# snakecase 0.4.0.9012
bug fix in dev version: protect works now for beginning and end of substrings and not anymore only for complete substrings.
# snakecase 0.4.0.9011
Fix bug for `character(0)` in combination with `postprocess`
# snakecase 0.4.0.9010
Input of `replace special character` is now a character vector. It's entries have to be elements of `stringi::stri_trans_list()` or names of the transliteration dictionary list,
which comes with this package. This update enables users to transliterate strings from different encodings, in a flexible way. For example UTF8 to Ascii, ... .
# snakecase 0.4.0.9009
* provided aliases `"all_caps"`, `"lower_camel"` and `"upper_camel"` for `"screaming_snake"`, `"small_camel"` and `"big_camel"`.
# snakecase 0.4.0.9008
* small bug fix for upper_lower/lower_upper regarding the behaviour for the combination of preprocess and protect (similar to an earlier bug in the camel cases).
# snakecase 0.4.0.9007
* small bug fix for behaviour of upper_lower/lower_upper. Now substrings with
without alphabetical characters are ignored.
# snakecase 0.4.0.9006
* new implemented cases: "none", "mixed", "upper_lower", "lower_upper".
# snakecase 0.4.0.9005
* empty_fill runs again in the end, before the pre and postprocess
* fixed bug: `to_any_case("r.aStudio", protect = "a", postprocess = "-", case = "big_camel")` will now
correctly return "R-.AStudio" (so the protection will be triggered by the input and not by the output). In contrast `protect = A` will yield in unprotected output (`-A-`)
# snakecase 0.4.0.9004
* empty_fill runs now at the beginning of to any case function (after the first parsing)
and a second parsing is introduced in case anything is filled.
# snakecase 0.4.0.9003
* fixed bug in camelcases, for letters after protected symbols (usually one wouldn't
protect in these cases anyway...)
# snakecase 0.4.0.9002
* implemented `check_design_rule()` (not exported)
* resolved bugs in other design options (also deleted one which is not valid for
screaming snake case)
# snakecase 0.4.0.9001
* included several parsingoptions for `to_any_case()`.
__1:__ "RRRStudio" -> "RRR_Studio" stays as default
__2:__ "RRRStudio -> RRRS_tudio"
__any other number__ will suppress the parsing (only spaces will be converted into "_")
# snakecase 0.4.0.9000
* This is the (stable) development version now. You can find snakecase on cran [here](https://CRAN.R-project.org/package=snakecase)
# snakecase 0.4.0
* CRAN submission
# snakecase 0.3.5.3
* changed order of the customizing arguments of `to_any_case()`
# snakecase 0.3.5.2
* fixed bug for combination of protect and postprocess. Therefore clarified and rewrote the internal order of `to_any_case()`
* resolved all internal build warnings and notes
# snakecase 0.3.5.1
* fixed bug in replace_special_characters combined with screaming snake case.
# snakecase 0.3.5
* any local special characters are now supported.
* added 2 arguments to `to_any_case()`: empty_fill, which allows to fill strings
matching to "" with the supplied string. unique_sep adds an integer suffix separated
with the supplied string, when not `NULL`.
* fixed a bug in to_snake_case_internal(). groups of digits are not separated in
between anymore.
* digits that are not direct next to each other, will be split via "_" in both camel case
versions. This is a meaningful exception. Otherwise information would be lost and
also the consistency rules in the readme wouldn't hold in this case.
# snakecase 0.3.4
* any_case() is now vectorised over pre-/postprocess, pre-/postfix for all case arguments
* introduces protect as (vectorised) argument to to_any_case(). it accepts regular expressions and cleans "_" or whatever the preprocessing did, between matches.
* some more tests, documentation and fixes.
# snakecase 0.3.3
* introduced case = "parsed" in to_any_case()
* introduced to_parsed_case()
# snakecase 0.3.2
* finished vignette (title: Caseconverters) and replaced the usage part in readme with it.
* changed behaviour in snake_case_internal to always treat whitespaces as underscores.
for whitespaces in output postprocess = " " is recommended.
# snakecase 0.3.1
* started testing `to_any_case` and removed a bug.
* added vignette
# snakecase 0.3.0
* supports behaviour for german umlauts on all platforms
* introduced internal function `to_snake_case_internal()` which does the preprocessing and simplifies all other functions (especially `to_any_case()`) a little bit.
* introduced `to_screaming_snake_case()`
* added arguments prefix, postfix and replace_special_characters to `to_any_case()`.
* completely renewed readme
* updated tests and highly modularized all tests. (just to_any_case lacks some tests now and in general more examples test cases have to be written)
# snakecase 0.2.2
* introduced `to_any_case()` (all functionality and documentation provided, but implementation has to be cleaned and also tests have to be written)
# snakecase 0.2.1
* fixed bug: `to_snake_case_dev(c("ssRRss"))` returns now `ss_r_rss` instead of`"ss_r_r_ss"`
* `to_snake_case()` now treats only spaces like underscores now (not dots anymore)
* functionality to treat different stuff like dots will be added via a new function:
`to_any_case()`, which will wrap the other three and will have pre- and postprocess arguments
# snakecase 0.2.0
* renamed the single input parameters consistent to `string` (without deprecating
the old name before, since the package was in early dev-stage anyway).
* started a to develop and implement consistent logic (which still has to be better documented in the readme)
* introduced tests for more hard coded examples and the logic behind it (still more
hardcoded examples and a third part of the logic have to be tested)
* internal logic has been simplified and modularized a lot, which makes it easier
to maintain and introduce more high-level features in the future
* added integrated tests via AppVeyor on windows
* added badges for cran status and code coverage to readme
# snakecase 0.1.0
* Introduced `to_snake_case()` which converts strings to snake_case.
* added functions `to_small_camel_case()` and `to_big_camel_case()` which internally
build up on `to_snake_case()` and convert to the appropriate target case.
* added basic hard coded tests
* added integrated tests on linux via travis.ci
snakecase/R/ 0000755 0001762 0000144 00000000000 13472230504 012410 5 ustar ligges users snakecase/R/parsing_helpers_internal.R 0000644 0001762 0000144 00000005535 13471620610 017624 0 ustar ligges users #' Parsing helpers
#'
#' Mainly for usage within \code{to_parsed_case_internal}
#'
#' @param string A string.
#'
#' @return A partly parsed character vector.
#'
#' @author Malte Grosser, \email{malte.grosser@@gmail.com}
#'
#' @keywords utilities
#'
#' @name parsing_helpers
#'
#' @rdname parsing_helpers
#'
parse1_pat_cap_smalls <- function(string) {
# Inserts underscores around groups of one upper case followed by lower case letters (or digits)
# RStudio.V11 -> R_Studio_.V11
pat_cap_smalls <- "([:upper:][:lower:]+)"
string <- stringr::str_replace_all(string, pat_cap_smalls, "_\\1_")
string}
#' @rdname parsing_helpers
parse2_pat_digits <- function(string) {
# Inserts underscores around groups of digts
# RStudio.V11 -> RStudio.V_11_
pat_digits <- "(\\d+)"
string <- stringr::str_replace_all(string, pat_digits, "_\\1_")
string}
#' @rdname parsing_helpers
parse3_pat_caps <- function(string) {
# Inserts underscores around all capital letter groups with length >= 2
# RStudio.V11 -> _RS_tudio.V11
pat_caps <- "([:upper:]{2,})"
string <- stringr::str_replace_all(string, pat_caps, "_\\1_")
string}
#' @rdname parsing_helpers
parse4_pat_cap <- function(string) {
# Inserts underscores around all capital letter groups with length = 1 that
# don't have a capital letter in front of them and not a capital or small letter behind them
# RStudio.V11 -> RStudio._V_11
pat_cap <- "((? RStudio_._V11
pat_non_alnums <- "([^[:alnum:]])"
string <- stringr::str_replace_all(string, pat_non_alnums, "_\\1_")
string}
#' @rdname parsing_helpers
parse6_mark_digits = function(string) {
# Inserts _ and space between non-alphanumerics and digits
digit_marker_before <- "(?<=[^_|\\d])(\\d)"
digit_marker_after <- "(\\d)(?=[^_|\\d])"
string <- stringr::str_replace_all(string, digit_marker_before, "_ \\1")
string <- stringr::str_replace_all(string, digit_marker_after , "\\1 _")
string
}
#' @rdname parsing_helpers
parse7_pat_caps_smalls = function(string) {
# Inserts underscores around of one or more upper case letters possibly followed by lower case letters
pat_caps_smalls <- "([:upper:]+[:lower:]*)"
string <- stringr::str_replace_all(string, pat_caps_smalls, "_\\1_")
string
}
#' @rdname parsing_helpers
parse8_pat_smalls_after_non_alnums = function(string) {
# Inserts underscores around of one or more upper case letters possibly followed by lower case letters
pat_smalls_after_non_alnums <- "((?