2

I have look into rJava and checked out a video on RCaller, but in all examples I saw people are only calling native R functions. I have found no way of loading a *.r file and using its content.

The main question is: How to integrate a custom Rscript in Java, so that I can call my custom-made R functions through java?

The thing that I want to do is to create a simple GUI with images loaded from folders, buttons and be able to call my custom R functions on click and dynamically swapping images depending on outcomes(the logic would be in R).

1
  • If a direct Java -> R is not possible then you could always adopt Java -> (JNI) -> C / C++ -> R Commented May 16, 2014 at 13:42

3 Answers 3

2

Good practice would be to hide the R code behind an abstraction, i.e., an interface. Once the interface has been defined, call rJavax::setJavaImplementation() to define an R reference class that implements the interface.

An alternative solution (but not a direct answer to your question) would be to use e.g. the gWidgets package to create your GUI in R. That should be much easier than attempting the same with Java/Swing.

Sign up to request clarification or add additional context in comments.

Comments

0

you can still stay with RCaller using R's source() function to open and read an external R script and call its content using RCaller.

Comments

0

This seems to be an old post. However one solution would be to use source('path of R script') R command in your Java code to import the functionality written in external R script.

There is also a blog on integration of R with Java [http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/][1] which describes the process under heading 'Calling User-defined R functions in Java'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.