Skip to content

Commit 4b7a181

Browse files
jonthegeekhadley
authored andcommitted
Added str_to_sentence function. (#271)
* Added str_to_sentence function. * Added bullet in NEWS.md * Fixed line endings.
1 parent cec6a66 commit 4b7a181

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export(str_squish)
3737
export(str_sub)
3838
export(str_subset)
3939
export(str_to_lower)
40+
export(str_to_sentence)
4041
export(str_to_title)
4142
export(str_to_upper)
4243
export(str_trim)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* `str_subset()`, `str_detect()`, and `str_which()` gets `negate` argument,
77
which is useful when you want the elements that do NOT match (#259,
88
@yutannihilation).
9+
10+
* New `str_to_sentence()` function to capitalize with sentence case
11+
(@jonthegeek, #202)
912

1013
# stringr 1.3.1
1114

R/case.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' str_to_upper(dog)
99
#' str_to_lower(dog)
1010
#' str_to_title(dog)
11+
#' str_to_sentence("the quick brown dog")
1112
#'
1213
#' # Locale matters!
1314
#' str_to_upper("i") # English
@@ -30,3 +31,11 @@ str_to_lower <- function(string, locale = "en") {
3031
str_to_title <- function(string, locale = "en") {
3132
stri_trans_totitle(string, opts_brkiter = stri_opts_brkiter(locale = locale))
3233
}
34+
#' @export
35+
#' @rdname case
36+
str_to_sentence <- function(string, locale = "en") {
37+
stri_trans_totitle(
38+
string,
39+
opts_brkiter = stri_opts_brkiter(type = "sentence", locale = locale)
40+
)
41+
}

man/case.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-case.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ test_that("to_upper and to_lower have equivalent base versions", {
1010
test_that("to_title creates one capital letter per word", {
1111
expect_equal(str_count(x, "\\W+"), str_count(str_to_title(x), "[[:upper:]]"))
1212
})
13+
14+
test_that("to_sentence capitalizes just the first letter", {
15+
expect_identical(str_to_sentence("a Test"), "A test")
16+
})

0 commit comments

Comments
 (0)