[
https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ian Cook updated ARROW-13118:
-----------------------------
Description:
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.
was:
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 awfully 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}
Maybe 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.
> [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
> Assignee: Ian Cook
> Priority: Major
> Fix For: 6.0.0
>
>
> 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.3.4#803005)