user3507046
user3507046

Reputation: 125

Calling custom R functions from Java

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).

Upvotes: 2

Views: 1010

Answers (3)

Rajeev Singh
Rajeev Singh

Reputation: 504

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'

Upvotes: 0

jbytecode
jbytecode

Reputation: 679

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.

Upvotes: 0

Michael Lawrence
Michael Lawrence

Reputation: 1021

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.

Upvotes: 2

Related Questions