Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean_names: support abbreviations argument of snakecase::to_any_case? #283

Closed
gregrs-uk opened this issue Apr 2, 2019 · 3 comments · Fixed by #340
Closed

clean_names: support abbreviations argument of snakecase::to_any_case? #283

gregrs-uk opened this issue Apr 2, 2019 · 3 comments · Fixed by #340
Milestone

Comments

@gregrs-uk
Copy link

Could clean_names support passing an abbreviations argument to the abbreviations argument of snakecase::to_any_case?

My use case for this would be to keep certain abbreviations e.g. "ID" capitalised when using clean_names to convert column names to UpperCamel.

library(magrittr)

# ID is converted to Id
tibble::tibble("person ID" = c(1)) %>%
  janitor::clean_names("upper_camel")
#> # A tibble: 1 x 1
#>   PersonId
#>      <dbl>
#> 1        1

# that's what happens by default using to_any_case
snakecase::to_any_case("Person ID", "upper_camel")
#> [1] "PersonId"

# but you can pass the abbreviations argument
snakecase::to_any_case("Person ID", "upper_camel", abbreviations = c("ID"))
#> [1] "PersonID"

Created on 2019-04-02 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       macOS Sierra 10.12.6        
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_GB.UTF-8                 
#>  ctype    en_GB.UTF-8                 
#>  tz       Europe/London               
#>  date     2019-04-02                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.5.2)
#>  backports     1.1.3   2018-12-14 [1] CRAN (R 3.5.0)
#>  callr         3.1.1   2018-12-21 [1] CRAN (R 3.5.0)
#>  cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.2)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.0)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.0)
#>  devtools      2.0.1   2018-10-26 [1] CRAN (R 3.5.1)
#>  digest        0.6.18  2018-10-10 [1] CRAN (R 3.5.0)
#>  evaluate      0.13    2019-02-12 [1] CRAN (R 3.5.2)
#>  fansi         0.4.0   2018-10-05 [1] CRAN (R 3.5.0)
#>  fs            1.2.6   2018-08-23 [1] CRAN (R 3.5.0)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.5.2)
#>  highr         0.7     2018-06-09 [1] CRAN (R 3.5.0)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.5.0)
#>  janitor       1.1.1   2018-07-31 [1] CRAN (R 3.5.0)
#>  knitr         1.21    2018-12-10 [1] CRAN (R 3.5.1)
#>  magrittr    * 1.5     2014-11-22 [1] CRAN (R 3.5.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.0)
#>  pillar        1.3.1   2018-12-15 [1] CRAN (R 3.5.0)
#>  pkgbuild      1.0.2   2018-10-16 [1] CRAN (R 3.5.0)
#>  pkgconfig     2.0.2   2018-08-16 [1] CRAN (R 3.5.0)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.0)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.0)
#>  processx      3.2.1   2018-12-05 [1] CRAN (R 3.5.0)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.0)
#>  R6            2.4.0   2019-02-14 [1] CRAN (R 3.5.2)
#>  Rcpp          1.0.1   2019-03-17 [1] CRAN (R 3.5.2)
#>  remotes       2.0.2   2018-10-30 [1] CRAN (R 3.5.0)
#>  rlang         0.3.1   2019-01-08 [1] CRAN (R 3.5.2)
#>  rmarkdown     1.11    2018-12-08 [1] CRAN (R 3.5.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.0)
#>  snakecase     0.9.2   2018-08-14 [1] CRAN (R 3.5.0)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.5.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.5.2)
#>  testthat      2.0.1   2018-10-13 [1] CRAN (R 3.5.0)
#>  tibble        2.1.1   2019-03-16 [1] CRAN (R 3.5.2)
#>  usethis       1.4.0   2018-08-14 [1] CRAN (R 3.5.0)
#>  utf8          1.1.4   2018-05-24 [1] CRAN (R 3.5.0)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.0)
#>  xfun          0.5     2019-02-20 [1] CRAN (R 3.5.2)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library
@sfirke
Copy link
Owner

sfirke commented Mar 7, 2020

@billdenney what do you think, while we are at it with clean_names? I could see either exposing the abbreviations argument in clean_names and passing it through, or adding ... so users can pass through anything to to_any_case's other arguments.

@sfirke sfirke added this to the v2.0 milestone Mar 7, 2020
@billdenney
Copy link
Collaborator

Yes, with #340, all options to snakecase::to_any_case() will be exposed, so if a formatting is available there, it will be available in clean_names().

@gregrs-uk
Copy link
Author

Thank you both. Reprex below showing the new functionality in case it's useful to anyone:

library(magrittr)

# ID is converted to Id
tibble::tibble("person ID" = c(1)) %>%
  janitor::clean_names("upper_camel")
#> # A tibble: 1 x 1
#>   PersonId
#>      <dbl>
#> 1        1

# we can now pass the abbreviations argument along to snakecase::to_any_case
tibble::tibble("person ID" = c(1)) %>%
  janitor::clean_names("upper_camel", abbreviations = "ID")
#> # A tibble: 1 x 1
#>   PersonID
#>      <dbl>
#> 1        1

Created on 2020-03-12 by the reprex package (v0.3.0)

sfirke added a commit that referenced this issue Dec 28, 2020
…functions (#418)

* include examples of clean_names features that rely on snakecase::to_any_case, like #271 and #283
* update README, index, and dirty_data.xlsx to have even dirtier data and show functions like convert_to_date()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants