I am new to R and have been trying to use JRI. I am faced with the following issue -
- I have a set of values that I have received in my Java program which I have stored in a list.
- I have multiple such lists - each one representing a feature.
- I want to pass these lists to an R script to create a simple regression model. The script uses the lm() function.
I have come across multiple scripts which read from a file and load the data using read.table() (or other equivalent functions) before calling 'lm()'. In this particular case, I do not want to write to a file(create a new file) and again read from that file into memory - as I already have the data in memory.
Is there a way for me to pass this list from Java to the R script directly so that it can be used like a data frame? Can I pass this list as an argument?
I have searched a lot, but couldn't find anything similar. Any pointers would really be appreciated.
Very easy using
rJava
.java code side
I create a dummy class that generate some values.
r code side
Using
rjava
package , I create an R object ( a pointer to the java object), I call the generator and I get the numeric values.Then you do the regression like this :