Skip to content
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

Could not set static function to a variable in R #320

Open
gaocegege opened this issue Jun 7, 2017 · 4 comments
Open

Could not set static function to a variable in R #320

gaocegege opened this issue Jun 7, 2017 · 4 comments

Comments

@gaocegege
Copy link

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.

@akbertram
Copy link
Member

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.

@gaocegege gaocegege changed the title [It seems to be a bug] Could not Set static function to a variable in R Could not Set static function to a variable in R Jun 7, 2017
@gaocegege gaocegege changed the title Could not Set static function to a variable in R Could not set static function to a variable in R Jun 7, 2017
@jeremydouglass
Copy link

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?

@akbertram
Copy link
Member

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!

@jeremydouglass
Copy link

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

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants