paleolimbot opened a new pull request #12432:
URL: https://github.com/apache/arrow/pull/12432
This PR defines the `Math` group generic for `ArrowDatum`, which allows
several more base R functions to be used with `Array` and `Scalar` objects.
This is particularly useful for exposing decimal math kernels (which are
non-existent in R to my knowledge) without having to go through a `Table`/dplyr
query.
``` r
# remotes::install_github("paleolimbot/arrow/r@r-math-generics")
library(arrow, warn.conflicts = FALSE)
dec <- Array$create(12.34)$cast(decimal128(10, 2))
floor(dec)
#> Array
#> <decimal128(10, 2)>
#> [
#> 12.00
#> ]
round(dec, digits = 1)
#> Array
#> <decimal128(10, 2)>
#> [
#> 12.30
#> ]
cos(dec)
#> Array
#> <double>
#> [
#> 0.9744873987650982
#> ]
acos(dec - 12L)
#> Array
#> <double>
#> [
#> 1.2238794292677349
#> ]
# binary ops already worked
dec + 1L
#> Array
#> <decimal128(13, 2)>
#> [
#> 13.34
#> ]
dec * dec
#> Array
#> <decimal128(21, 4)>
#> [
#> 152.2756
#> ]
dec + dec
#> Array
#> <decimal128(11, 2)>
#> [
#> 24.68
#> ]
dec ^ dec
#> Array
#> <double>
#> [
#> 2.9297399331911957e+13
#> ]
```
I imagine at some point the code in arrow-datum.R and compute.R should be
refactored to use all the translations that we've nicely defined in
dplyr-funcs-*.R (there's a lot of overlap).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]