Closed aornugent closed 4 years ago
Ah! The brackets need to be specified in sep_in
:
rename_all(x, to_any_case, sep_in = "\\(|\\)", transliterations = c("\\$" = "AUD")) %>%
colnames(.)
#> [1] "off_farm_contracts_aud"
Hi @aornugent you could also use
library(tidyverse)
library(snakecase)
x <- tibble(`Off farm contracts ($)` = NA)
rename_all(x, to_any_case, sep_in = "[^[:alnum:]|\\$]",
transliterations = c("\\$" = "AUD")) %>%
colnames(.)
#> [1] "off_farm_contracts_aud"
Created on 2020-03-23 by the reprex package (v0.3.0)
The default (sep_in = "[^[:alnum:]"
) treats non-alphanumeric characters like "$" as a separator. Therefore, you can't match it with transliterations
without changing sep_in
.
Your solution sep_in = "\\(|\\)"
treats "(" and ")" (and " ", "_", which are always added internaly) as separators. Therefore, "$" is kept in the name and you can match it via transliterations
.
sep_in = "[^[:alnum:]|\\$]"
as shown above would treat every non-alphanumeric character except $ as a separator. I believe this is a bit more robust as other special characters like ".", ",", "-" etc. can not appear in the output.
Hia, love the package.
I can't quite get the transliterations to do what I want:
Escaping the
$
with\\$
gives me the correct behaviour. Now I'd like to leveragesnakecase
to also format the remaining text:Is there something special needed to treat the
$
character as a transliteration?