ianmcook commented on a change in pull request #9878:
URL: https://github.com/apache/arrow/pull/9878#discussion_r606880444
##########
File path: r/R/dplyr.R
##########
@@ -434,6 +438,75 @@ build_function_list <- function(FUN) {
)
}
+arrow_r_string_replace_function <- function(FUN, max_replacements) {
+ function(pattern, replacement, x, ignore.case = FALSE, fixed = FALSE) {
+ if (ignore.case) {
+ if (fixed) {
+ pattern <- paste0("(?i)\\Q", pattern, "\\E")
+ } else {
+ pattern <- paste0("(?i)", pattern)
+ }
+ }
+ FUN(
+ ifelse(fixed && !ignore.case, "replace_substring",
"replace_substring_regex"),
+ x,
+ options = list(
+ pattern = pattern,
+ replacement = replacement,
+ max_replacements = max_replacements
+ )
+ )
+ }
+}
+
+arrow_stringr_string_replace_function <- function(FUN, max_replacements) {
+ function(string, pattern, replacement) {
+ # Assign stringr pattern modifier functions locally
Review comment:
I considered this and concluded that there were several reasons this
approach is preferable.
This approach avoids requiring the user to have stringr installed or loaded.
Since we do not need stringr to be installed or loaded for the `str_replace()`
and `str_replace_all()` functions to work with Arrow, it would seem strange to
require stringr to be installed or loaded to use these pattern modifier
functions.
Also, although stringr exports the pattern modifier functions and their
arguments are documented and very unlikely to change without prior deprecation
warnings, the structure of the objects they _return_ is an internal stringr
implementation detail which we should not depend on. The stringr help entry for
these modifier functions lacks a Value section, so they could conceivably
change anytime.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]