You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Raúl Cumplido (Jira)" <ji...@apache.org> on 2022/10/06 09:10:00 UTC

[jira] [Updated] (ARROW-13118) [R] Improve handling of R scalars in some nse_funcs

     [ https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Raúl Cumplido updated ARROW-13118:
----------------------------------
    Fix Version/s:     (was: 10.0.0)

> [R] Improve handling of R scalars in some nse_funcs
> ---------------------------------------------------
>
>                 Key: ARROW-13118
>                 URL: https://issues.apache.org/jira/browse/ARROW-13118
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: R
>            Reporter: Ian Cook
>            Priority: Major
>
> Some of the functions in {{nse_funcs}} do not behave properly when passed R scalar input in expressions in dplyr verbs. Some examples:
> {code:r}
> Table$create(x = 1) %>% mutate(as.character(42))
> Table$create(x = 1) %>% mutate(is.character(("foo")))
> Table$create(x = 1) %>% mutate(nchar("foo"))
> Table$create(x = 1) %>% mutate(is.infinite(Inf))
> {code}
> This could be resolved by using {{build_expr()}} instead of {{Expression$create()}}, but {{build_expr()}} is somewhat heavy. The only part of it we really need to make this work is this:
> {code:r}
>     args <- lapply(args, function(x) {
>       if (!inherits(x, "Expression")) {
>         x <- Expression$scalar(x)
>       }
>       x
>     }){code}
> If {{build_expr()}} is too heavy, we could make a function called {{wrap_r_scalar}}, like this:
> {code:r}
> wrap_r_scalar <- function(x) {
>   if (!inherits(x "Expression")) {
>     assert_that(
>       length(x) == 1,
>       msg = "Literal vectors of length != 1 not supported"
>     )
>     Expression$scalar(x)
>   } else {
>     x
>   }
> }
> {code}
> and use it as needed in various of the {{nse_funcs}} functions.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)