Tazinho / snakecase

🐍🐍🐍 A systematic approach to parse strings and automate the conversion to snake_case, UpperCamelCase or any other case.
https://tazinho.github.io/snakecase/
GNU General Public License v3.0
146 stars 9 forks source link

abbreviations argument appears to be ignored with case="snake" #190

Closed billdenney closed 3 years ago

billdenney commented 3 years ago

Maybe related to #183, and definitely related to sfirke/janitor#433.

The abbreviations argument appears to be ignored with case="snake".

snakecase::to_any_case(
  string=c("ID", "Column-2"),
  case="snake",
  abbreviations="ID"
)
#> [1] "id"       "column_2"

snakecase::to_any_case(
  string=c("ID", "Column-2"),
  case="upper_camel",
  abbreviations="ID"
)
#> [1] "ID"      "Column2"

Created on 2021-02-12 by the reprex package (v1.0.0)

Tazinho commented 3 years ago

Hi @billdenney, this is actually documented behaviour. From the abbreviations point in the Readme:

Abbreviations are consistently formatted regarding the supplied case. However, for title-, mixed-, lower-camel- and upper-camel-case the formatting is specified by the formatting of the input.

The ratio behind this is that the argument was mainly introduced to parse abbreviations out of strangely formatted cases, i.e. from the Readme:

to_snake_case(c("HHcity", "IDTable1", "KEYtable2", "newUSElections"),
              abbreviations = c("HH", "ID", "KEY", "US"))
## [1] "hh_city"          "id_table_1"       "key_table_2"     
## [4] "new_us_elections"

The option to format the abbreviations for title-, mixed-, lower-camel- and upper-camel-case is mainly a small bonus. I didn't expect, that anyone would like to have upper case abbreviations within otherwise snake case formatted names.

If you agree, I'd close here. Otherwise, we can make it a feature request.

Anyway, I need to finish some stuff and will probably work on snakecase again in May or June with the goal of a general overhaul of the abbreviation argument (as it's currently a pain from a consistency point of view) and possibly a stable V1.0 release. So for the user in sfirke/janitor#433 I'd currently recommend some manual preprocessing.

billdenney commented 3 years ago

Ah, I read the help for abbreviations, but I missed that part. In my opinion, if this is expected behavior, it can be closed.