You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/20 17:50:43 UTC

[GitHub] [arrow] paleolimbot commented on pull request #13397: ARROW-16444: [R] Implement user-defined scalar functions in R bindings

paleolimbot commented on PR #13397:
URL: https://github.com/apache/arrow/pull/13397#issuecomment-1160707504

   All good points and thank you for taking a look! Your edit did the trick, although the segfault may have been due to something about turning a `Scalar` into an `Array`:
   
   ``` r
   # remotes::install_github("apache/arrow/r#13397")
   library(arrow, warn.conflicts = FALSE)
   
   fun <- arrow:::arrow_scalar_function(
     int32(),
     int64(),
     function(x, y) {
       y[[1]]$cast(int64())
     }
   )
   
   arrow:::register_scalar_function("my_test_scalar_function", fun)
   
   # works!
   call_function("my_test_scalar_function", Array$create(1L))
   #> Array
   #> <int64>
   #> [
   #>   1
   #> ]
   
   # segfaults!
   # call_function("my_test_scalar_function", Scalar$create(1L))
   ```
   
   <sup>Created on 2022-06-20 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>
   
   > you will get a test failure saying the function is already registered
   
   It seems there's no way to unregister a function...if there were, I could unregister it in the test. I changed the `AddFunction()` call to overwrite the existing function for now but that's probably not a good long-term choice.
   
    


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org