renjin
renjin copied to clipboard
Could not set static function to a variable in R
Hi, I am using renjin to implement R Language mode for Processing. And I find a issue:
There is a function in RLangPApplet
:
class RLangPApplet {
static public final float radians(float degrees) {
return degrees * DEG_TO_RAD;
}
}
And I put a RLangPApplet
instance into R context by this.renjinEngine.put("processing", instance);
When I call processing$radians
, it works. But when I run radians = processing$radians
, it raises an error: https://pastebin.com/Lxzh4Bb2
FYI: When I do:
import(rprocessing.RLangPApplet)
radians = RLangPApplet$radians
It works again. I am wondering if there is a bug or I miss something.
Your "radians" method is a static java method. If you want only to expose the static methods in RLangPApplet, then you use the following instead:
this.renjinEngine.put("processing", RLangPApplet.class);
On the other hand, it's pretty reasonable to expect to be able to access static methods/fields via an instance, so we should probably fix this in Renjin.
On the other hand, it's pretty reasonable to expect to be able to access static methods/fields via an instance, so we should probably fix this in Renjin.
In order to access static methods/fields via an instance in Renjin -- what would it take? Should this be filled as a separate issue / feature request; would it require significant development effort?
I think this should not be too difficult. Take a look at the class in the org.renjin.invoke.reflection package to get started.
If you're interested in us implementing it for you, consider our Renjin Enterprise Support package!