diff --git a/r/R/arrow-datum.R b/r/R/arrow-datum.R index 4ec5f8f9d65..39362628bb4 100644 --- a/r/R/arrow-datum.R +++ b/r/R/arrow-datum.R @@ -123,7 +123,7 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) { x, options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN) ), - sqrt = eval_array_expression("power_checked", x, 0.5), + sqrt = eval_array_expression("sqrt_checked", x), exp = eval_array_expression("power_checked", exp(1), x), signif = , expm1 = , diff --git a/r/R/dplyr-funcs-math.R b/r/R/dplyr-funcs-math.R index b92c202d048..0ba2ddc856e 100644 --- a/r/R/dplyr-funcs-math.R +++ b/r/R/dplyr-funcs-math.R @@ -80,4 +80,19 @@ register_bindings_math <- function() { options = list(ndigits = digits, round_mode = RoundMode$HALF_TO_EVEN) ) }) + + register_binding("sqrt", function(x) { + build_expr( + "sqrt_checked", + x + ) + }) + + register_binding("exp", function(x) { + build_expr( + "power_checked", + exp(1), + x + ) + }) } diff --git a/r/tests/testthat/test-dplyr-funcs-math.R b/r/tests/testthat/test-dplyr-funcs-math.R index dd982c99428..47a9f0b7c02 100644 --- a/r/tests/testthat/test-dplyr-funcs-math.R +++ b/r/tests/testthat/test-dplyr-funcs-math.R @@ -330,3 +330,25 @@ test_that("floor division maintains type consistency with R", { df ) }) + +test_that("exp()", { + df <- tibble(x = c(1:5, NA)) + + compare_dplyr_binding( + .input %>% + mutate(y = exp(x)) %>% + collect(), + df + ) +}) + +test_that("sqrt()", { + df <- tibble(x = c(1:5, NA)) + + compare_dplyr_binding( + .input %>% + mutate(y = sqrt(x)) %>% + collect(), + df + ) +})