Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ Collate:
'utils.R'
'zzz.R'
VignetteBuilder: knitr
RoxygenNote: 5.0.1.9000
RoxygenNote: 6.0.1
Repository: CRAN

7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ lettercase
====


2018-?-? : Version 0.15.0
----
- New Features:
-- CamelCase to snake_case (Issue #1)


2016-03-03 : Version 0.13.0
----
First CRAN Release
Expand All @@ -10,3 +16,4 @@ First CRAN Release
-- Update README.md
-- Improve vignettes
- Ready for CRAN release

10 changes: 10 additions & 0 deletions R/str_snake_case.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' * multiple adjacent undescores are replaced by single underscore
#' * Underscores at beginning or end of names are dropped
#'
#' @note The CamelCase conversion is adapted from an approach described on [Stack Overflow](https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case/1176023#1176023).
#'
#' @examples
#' str_snake_case( "One Flew Over The Cuckoo's Nest" )
#' str_snake_case( "Catch-22" ) # catch_22
Expand All @@ -22,6 +24,10 @@
#' str_snake_case( "Catch 22" )
#' str_snake_case( " Catch 22 " )
#'
#' str_snake_case( "patient.dob" )
#' str_snake_case( "patientDob" )
#' str_snake_case( "PatientDob" )
#'
#' @rdname str_snake_case
#' @aliases str_snake_case
#' @export
Expand All @@ -35,6 +41,10 @@ str_snake_case <- function(

# for( ac in acronyms ) string <- gsub( tolower(ac), ac, string )

# The first two lines accommodate CamelCase: https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case/1176023#1176023
string <- gsub("(.)([A-Z][a-z]+)" , "\\1_\\2", string, perl=TRUE ) # Separate w/ dashes based on capitalization
string <- gsub("([a-z0-9])([A-Z])", "\\1_\\2", string, perl=TRUE )

string <- gsub( '[^\\w\\s-\\.]', '', string, perl=TRUE )
string <- tolower(string)
string <- gsub( pattern_separators, '_', string, perl=TRUE )
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Lettercase
[![Downloads](http://cranlogs.r-pkg.org/badges/lettercase?color=brightgreen)](http://www.r-pkg.org/pkg/lettercase)
[![](http://cranlogs.r-pkg.org/badges/grand-total/lettercase)](http://cran.rstudio.com/web/packages/lettercase/index.html)
[![software impact](http://depsy.org/api/package/r/lettercase/badge.svg)](http://depsy.org/package/r/lettercase)
[![Build Status](https://travis-ci.org/decisionpatterns/lettercase.svg?branch=dev)](https://travis-ci.org/decisionpatterns/lettercase)


Utilities for formatting strings and character vectors to for capitalization,
Expand Down
1 change: 0 additions & 1 deletion man/lettercase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/make_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/make_str_replace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions man/patterns.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/str_cap_words.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/str_collapse_whitespace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/str_delete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions man/str_is.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/str_sentence_case.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/str_snake_case.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/str_spine_case.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/str_title_case.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/str_transform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/str_ucfirst.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions man/str_uppercase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions man/string_transformations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions tests/testthat/test-snake_case.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ str_snake_case( 'mission_of_burma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'mission-of-burma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'mission.of.burma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'Mission of Burma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'MissionOfBurma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'missionOfBurma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( ' .mission.of.burma. ' ) %>% expect_equal( 'mission_of_burma' )

# str_snake_case( 'mission-of-burma' ) %>% expect_equal( 'mission_of_burma' )
# str_snake_case( 'mission_of_burma' ) %>% expect_equal( 'mission_of_burma' )
# str_snake_case( 'MissionOfBurma' ) %>% expect_equal( 'mission_of_burma' )
str_snake_case( 'mission' ) %>% expect_equal( 'mission' )
str_snake_case( 'Mission' ) %>% expect_equal( 'mission' )

str_snake_case( "Catch-22" ) %>% expect_equal( 'catch_22' )
str_snake_case( "Catch.22" ) %>% expect_equal( 'catch_22' )
str_snake_case( "Catch_22" ) %>% expect_equal( 'catch_22' )
str_snake_case( "Catch 22" ) %>% expect_equal( 'catch_22' )
str_snake_case( " Catch 22 " ) %>% expect_equal( 'catch_22' )

str_snake_case( "patient.dob" ) %>% expect_equal( 'patient_dob' )
str_snake_case( "patientDob" ) %>% expect_equal( 'patient_dob' )
str_snake_case( "PatientDob" ) %>% expect_equal( 'patient_dob' )