Skip to content
Closed
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
6 changes: 6 additions & 0 deletions r/R/dplyr-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ arrow_string_join_function <- function(null_handling, null_replacement = NULL) {
# str_to_lower
# str_to_upper
# str_to_title
# str_to_sentence
#
# Arrow locale will be supported with ARROW-14126
stop_if_locale_provided <- function(locale) {
Expand All @@ -367,6 +368,11 @@ nse_funcs$str_to_title <- function(string, locale = "en") {
Expression$create("utf8_title", string)
}

nse_funcs$str_to_sentence <- function(string, locale = "en") {
stop_if_locale_provided(locale)
Expression$create("utf8_capitalize", string)
}

nse_funcs$str_trim <- function(string, side = c("both", "left", "right")) {
side <- match.arg(side)
trim_fun <- switch(side,
Expand Down
1 change: 1 addition & 0 deletions r/R/expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# str_to_lower is defined in dplyr-functions.R
# str_to_title is defined in dplyr-functions.R
# str_to_upper is defined in dplyr-functions.R
# str_to_sentence is defined in dplyr-functions.R
# str_trim is defined in dplyr-functions.R
"stri_reverse" = "utf8_reverse",
# substr is defined in dplyr-functions.R
Expand Down
24 changes: 24 additions & 0 deletions r/tests/testthat/test-dplyr-funcs-string.R
Original file line number Diff line number Diff line change
Expand Up @@ -1336,3 +1336,27 @@ test_that("str_starts, str_ends, startsWith, endsWith", {
df
)
})

test_that("str_to_sentence", {
df <- tibble(
one_sent = c("first word", "the second word", "the third word"),
two_sent = c("first word. second word? third word! fourth word",
"second word", "third word")
)

expect_dplyr_equal(
input %>%
mutate(sentence_case = str_to_sentence(one_sent)) %>%
collect(),
df
)

# there is something strange going on with str_to_sentence in stringr where
# it doesn't recognise `.` as a sentence end
expect_dplyr_error(
input %>%
mutate(sentence_case_two = str_to_sentence(two_sent)) %>%
collect(),
df
)
})