diff --git a/r/src/compute.cpp b/r/src/compute.cpp index 9670bd0bb6c..7698fdeee90 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -400,6 +400,14 @@ std::shared_ptr make_compute_options( step); } + if (func_name == "utf8_replace_slice" || func_name == "binary_replace_slice") { + using Options = arrow::compute::ReplaceSliceOptions; + + return std::make_shared(cpp11::as_cpp(options["start"]), + cpp11::as_cpp(options["stop"]), + cpp11::as_cpp(options["replacement"])); + } + if (func_name == "variance" || func_name == "stddev" || func_name == "hash_variance" || func_name == "hash_stddev") { using Options = arrow::compute::VarianceOptions; diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 7725888f02f..ecd54f51090 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -17,7 +17,7 @@ test_that("non-bound compute kernels using TrimOptions", { -skip_if_not_available("utf8proc") + skip_if_not_available("utf8proc") expect_equal( call_function( "utf8_trim", @@ -82,6 +82,27 @@ skip_if_not_available("utf8proc") ) }) +test_that("non-bound compute kernels using ReplaceSliceOptions", { + skip_if_not_available("utf8proc") + + expect_equal( + call_function( + "binary_replace_slice", + Array$create("I need to fix this string"), + options = list(start = 1, stop = 1, replacement = " don't") + ), + Array$create("I don't need to fix this string") + ) + + expect_equal( + call_function( + "utf8_replace_slice", + Array$create("I need to fix this string"), + options = list(start = 1, stop = 1, replacement = " don't") + ), + Array$create("I don't need to fix this string") + ) +}) test_that("non-bound compute kernels using ModeOptions", { expect_equal( as.vector(