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

2021-07-16 Thread Ian Cook (Jira)


[ 
https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17382214#comment-17382214
 ] 

Ian Cook commented on ARROW-13118:
--

This is solved for the {{is.*()}} type checking functions in 
[https://github.com/apache/arrow/pull/10724/]

> [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)


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

2021-06-24 Thread Ian Cook (Jira)


[ 
https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17368959#comment-17368959
 ] 

Ian Cook commented on ARROW-13118:
--

Yes, the examples above are simplistic; a case that better demonstrates the 
practical need for this is something like the {{case_when()}} function which we 
should be able to implement in the R bindings after ARROW-13064 is merged. 
Users often mix literal scalars and column references/expressions in the 
{{case_when()}} arguments.

> [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: 5.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 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


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

2021-06-21 Thread Neal Richardson (Jira)


[ 
https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17366837#comment-17366837
 ] 

Neal Richardson commented on ARROW-13118:
-

{{build_expr()}} isn't that heavy, it's basically a glorified switch statement 
to handle some special cases + the scalar wrapping you suggest + R function 
name mapping. So you could use it in more places if you want, though I'm not 
convinced of the utility–the examples you gave aren't that compelling. Is there 
a real use case you're trying to support?

> [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: 5.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 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


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

2021-06-18 Thread Ian Cook (Jira)


[ 
https://issues.apache.org/jira/browse/ARROW-13118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17365552#comment-17365552
 ] 

Ian Cook commented on ARROW-13118:
--

[~npr] what do you think? Does the solution described above (creating a 
{{wrap_r_scalar}} function) seem reasonable?

> [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: 5.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 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)