-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setArrayElement does not work on R array/vector #21
Comments
Hi Edoardo, R vectors should be immutable so it is questionable how the What you can use to update R vectors are R functions
|
Hi Steve, Thanks for the explanation and apologies for my limited knowledge of R vectors. Indeed, I agree with you on the fact that setArrayElement() should throw with an explanation when trying to use it on an R vector due to its immutability. Side question: is there a mutable collection in R on which the setElementArray() would work? Thank you |
no need for the apology. We thank you for your feedback! Please feel free to ask more questions and open more issues. We are also looking for a feedback on what features (Java interop, Spark integration, ...) are important for our users (including suggestions on new features!) and what R packages are essential for them. If you could share a bit about your use-case that would be fantastic, but I understand that that is not always possible. You can also reach me at stepan[dot]sindelar-at-oracle.com You can also check the reference manual for more examples.
the environments have reference semantics in R, but they are more like an object with fields referenced by name. Example:
another thing that you can do is to pass arrays from other languages to R. R should be able to handle them in most cases just as if they were vectors. If you come across R builtin functions that cannot handle them, let us know and we'll fix that. The simplest is to just use Java arrays:
you can create a
you can create your own implementation of the
or you can even use an array from another language like Ruby:
We may reconsider whether it makes sense to apply reference semantics in the last R code snippet:
as it would mean some R code that assumes vectors are immutable may not work with foreign arrays. I am attaching full example source code. |
Hi Steve, Thank you very much for your explanation. Much appreciated. I am trying to use Graal's Polyglot API to execute scripts written by the users of my platform. My basic requirement is to run JS scripts. However, I am experimenting with R as well because I believe it can bring added value to the system. My basic requirements for executing these scripts are:
I posted on GraalJS' github a few days ago: oracle/graaljs#45. One of the answers I got in that post suggested to create the guest variable in the host side already in the guest data type in order to meet the second requirement I mentioned above. This works great in JS and Python, and thanks to your advice I managed to make it work in R too (this is why I was trying to use setArrayElement). In that same post, @lukasstadler mentioned that there is currently a bug on the R side, due to which setting top level bindings with anything other than a native R data type causes the error I posted: I will send you an email with a more in depth description of my use case. Once again thanks for your help. |
Hi,
I am trying to use Value.setArrayElement() to populate a R vector from Java (host side).
I have tried the following:
Value rArray = guestLanguageContext.eval("R", "vector()");
rArray.setArrayElement(0, "somevalue");
While the empty vector is successfully created, calling setArrayElement() like that does not change the content of the R array.
Is it possible to use setArrayElement with an R array? Am I not doing it right or is this an issue with the R implementation?
Thanks
Edoardo.
The text was updated successfully, but these errors were encountered: