Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-13118

[R] Improve handling of R scalars in some nse_funcs

Add voteWatch issue
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • R
    • None

    Description

      Some of the functions in nse_funcs do not behave properly when passed R scalar input in expressions in dplyr verbs. Some examples:

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

      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:

          args <- lapply(args, function(x) {
            if (!inherits(x, "Expression")) {
              x <- Expression$scalar(x)
            }
            x
          })

      If build_expr() is too heavy, we could make a function called wrap_r_scalar, like this:

      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
        }
      }
      

      and use it as needed in various of the nse_funcs functions.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              icook Ian Cook

              Dates

                Created:
                Updated:

                Slack

                  Issue deployment