Skip to content

Commit c155e99

Browse files
authored
GH-43662: [R] Add binding to stringr::str_replace_na() (#47521)
### Rationale for this change Had no bindings for `stringr::str_replace_na()` ### What changes are included in this PR? Add those bindings ### Are these changes tested? Yes ### Are there any user-facing changes? Yep * GitHub Issue: #43662 Authored-by: Nic Crane <[email protected]> Signed-off-by: Nic Crane <[email protected]>
1 parent aedb752 commit c155e99

File tree

4 files changed

+196
-154
lines changed

4 files changed

+196
-154
lines changed

r/R/dplyr-funcs-doc.R

Lines changed: 5 additions & 4 deletions
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 222 R functions to the corresponding
24+
#' The package also has mappings of 223 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
@@ -83,7 +83,7 @@
8383
#' Functions can be called either as `pkg::fun()` or just `fun()`, i.e. both
8484
#' `str_sub()` and `stringr::str_sub()` work.
8585
#'
86-
#' In addition to these functions, you can call any of Arrow's 280 compute
86+
#' In addition to these functions, you can call any of Arrow's 281 compute
8787
#' functions directly. Arrow has many functions that don't map to an existing R
8888
#' function. In other cases where there is an R function mapping, you can still
8989
#' call the Arrow function directly if you don't want the adaptations that the R
@@ -216,8 +216,8 @@
216216
#'
217217
#' ## hms
218218
#'
219-
#' * [`as_hms()`][hms::as_hms()]
220-
#' * [`hms()`][hms::hms()]
219+
#' * [`as_hms()`][hms::as_hms()]: subsecond precision not supported for character input
220+
#' * [`hms()`][hms::hms()]: nanosecond times not supported
221221
#'
222222
#' ## lubridate
223223
#'
@@ -341,6 +341,7 @@
341341
#' * [`str_remove_all()`][stringr::str_remove_all()]
342342
#' * [`str_replace()`][stringr::str_replace()]
343343
#' * [`str_replace_all()`][stringr::str_replace_all()]
344+
#' * [`str_replace_na()`][stringr::str_replace_na()]
344345
#' * [`str_split()`][stringr::str_split()]: Case-insensitive string splitting and splitting into 0 parts not supported
345346
#' * [`str_starts()`][stringr::str_starts()]
346347
#' * [`str_sub()`][stringr::str_sub()]: `start` and `end` must be length 1

r/R/dplyr-funcs-string.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ register_bindings_string_regex <- function() {
402402
register_binding("stringr::str_remove", arrow_stringr_string_remove_function(1L))
403403
register_binding("stringr::str_remove_all", arrow_stringr_string_remove_function(-1L))
404404

405+
register_binding("stringr::str_replace_na", function(string, replacement = "NA") {
406+
if (!is.character(replacement) || length(replacement) != 1) {
407+
validation_error("`replacement` must be a single string")
408+
}
409+
Expression$create("coalesce", string, Expression$scalar(replacement))
410+
})
411+
405412
register_binding("base::strsplit", function(x, split, fixed = FALSE, perl = FALSE,
406413
useBytes = FALSE) {
407414
assert_that(is.string(split))

0 commit comments

Comments
 (0)