renjin icon indicating copy to clipboard operation
renjin copied to clipboard

Could not set static function to a variable in R

Open gaocegege opened this issue 7 years ago • 4 comments

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.

gaocegege avatar Jun 07 '17 07:06 gaocegege

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.

akbertram avatar Jun 07 '17 12:06 akbertram

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?

jeremydouglass avatar Aug 06 '19 17:08 jeremydouglass

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!

akbertram avatar Aug 16 '19 12:08 akbertram

Take a look at the class in the org.renjin.invoke.reflection package to get started.

Many thanks!

jeremydouglass avatar Aug 16 '19 15:08 jeremydouglass