Skip to content

Commit ad9279e

Browse files
authored
GH-48127: [R] stringr argument deprecation - add binding for stringr::str_ilike() and remove ignore_case argument for stringr::str_like() (#48262)
### Rationale for this change We have bindings to stringr but stringr updated ### What changes are included in this PR? Add new binding and warn re deprecation ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #48127 Authored-by: Nic Crane <[email protected]> Signed-off-by: Nic Crane <[email protected]>
1 parent 9c247a5 commit ad9279e

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

r/R/dplyr-funcs-doc.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#'
2222
#' The `arrow` package contains methods for 37 `dplyr` table functions, many of
2323
#' which are "verbs" that do transformations to one or more tables.
24-
#' The package also has mappings of 223 R functions to the corresponding
24+
#' The package also has mappings of 224 R functions to the corresponding
2525
#' functions in the Arrow compute library. These allow you to write code inside
2626
#' of `dplyr` methods that call R functions, including many in packages like
2727
#' `stringr` and `lubridate`, and they will get translated to Arrow and run
@@ -334,6 +334,7 @@
334334
#' * [`str_detect()`][stringr::str_detect()]
335335
#' * [`str_dup()`][stringr::str_dup()]
336336
#' * [`str_ends()`][stringr::str_ends()]
337+
#' * [`str_ilike()`][stringr::str_ilike()]
337338
#' * [`str_length()`][stringr::str_length()]
338339
#' * [`str_like()`][stringr::str_like()]
339340
#' * [`str_pad()`][stringr::str_pad()]

r/R/dplyr-funcs-string.R

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,31 @@ register_bindings_string_regex <- function() {
259259

260260
register_binding(
261261
"stringr::str_like",
262-
function(string, pattern, ignore_case = TRUE) {
262+
function(string, pattern, ignore_case) {
263+
# TODO: Remove ignore_case parameter after stringr removes it (stringr >= 2.0.0?)
264+
if (!missing(ignore_case)) {
265+
warning(
266+
"The `ignore_case` argument of `str_like()` is deprecated as of stringr 1.6.0.\n",
267+
"`str_like()` is always case sensitive.\n",
268+
"Use `str_ilike()` for case insensitive string matching.",
269+
call. = FALSE
270+
)
271+
}
272+
Expression$create(
273+
"match_like",
274+
string,
275+
options = list(pattern = pattern, ignore_case = FALSE)
276+
)
277+
}
278+
)
279+
280+
register_binding(
281+
"stringr::str_ilike",
282+
function(string, pattern) {
263283
Expression$create(
264284
"match_like",
265285
string,
266-
options = list(pattern = pattern, ignore_case = ignore_case)
286+
options = list(pattern = pattern, ignore_case = TRUE)
267287
)
268288
}
269289
)

r/man/acero.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/tests/testthat/test-dplyr-funcs-string.R

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ test_that("stri_reverse and arrow_ascii_reverse functions", {
889889
)
890890
})
891891

892-
test_that("str_like", {
892+
test_that("str_like and str_ilike", {
893893
df <- tibble(x = c("Foo and bar", "baz and qux and quux"))
894894

895895
# No match - entire string
@@ -899,51 +899,44 @@ test_that("str_like", {
899899
collect(),
900900
df
901901
)
902+
902903
# with namespacing
903904
compare_dplyr_binding(
904905
.input |>
905-
mutate(x = stringr::str_like(x, "baz")) |>
906+
mutate(x_like = stringr::str_like(x, "baz")) |>
907+
mutate(x_ilike = stringr::str_ilike(x, "foo%")) |>
906908
collect(),
907909
df
908910
)
909911

910912
# Match - entire string
911913
compare_dplyr_binding(
912914
.input |>
913-
mutate(x = str_like(x, "Foo and bar")) |>
915+
mutate(x_like = str_like(x, "foo and bar")) |>
916+
mutate(x_ilike = str_ilike(x, "foo and bar")) |>
914917
collect(),
915918
df
916919
)
917920

918921
# Wildcard
919922
compare_dplyr_binding(
920923
.input |>
921-
mutate(x = str_like(x, "f%", ignore_case = TRUE)) |>
922-
collect(),
923-
df
924-
)
925-
926-
# Ignore case
927-
compare_dplyr_binding(
928-
.input |>
929-
mutate(x = str_like(x, "f%", ignore_case = FALSE)) |>
924+
mutate(like_lower = str_like(x, "f%")) |>
925+
mutate(like_upper = str_like(x, "F%")) |>
926+
mutate(ilike_lower = str_ilike(x, "f%")) |>
927+
mutate(ilike_upper = str_ilike(x, "F%")) |>
928+
mutate(like_percent = str_like(x, "%baz%")) |>
929+
mutate(like_underscore = str_like(x, "_a%")) |>
930+
mutate(ilike_mixed = str_ilike(x, "%BAZ%")) |>
931+
mutate(ilike_underscore = str_ilike(x, "_a%")) |>
930932
collect(),
931933
df
932934
)
933935

934-
# Single character
935-
compare_dplyr_binding(
936-
.input |>
937-
mutate(x = str_like(x, "_a%")) |>
938-
collect(),
939-
df
940-
)
941-
942-
compare_dplyr_binding(
943-
.input |>
944-
mutate(x = str_like(x, "%baz%")) |>
945-
collect(),
946-
df
936+
x <- Expression$field_ref("x")
937+
expect_warning(
938+
call_binding("str_like", x, pattern = "f%", ignore_case = TRUE),
939+
"The `ignore_case` argument of `str_like\\(\\)` is deprecated"
947940
)
948941
})
949942

0 commit comments

Comments
 (0)