jri

Writing a csv file in R from Java using JRI

廉价感情. 提交于 2020-01-17 08:31:21
问题 Apologies in advance if this is obvious, but I can't seem to find an answer to it online. I was wondering if it is possible to write to a csv file in R from Java. For example, if I was to create normal data and write it to a csv file, I thought something like this might work: Rengine re=new Rengine(args, false, new TextConsole()); re.eval("write.csv(rnorm(100,50,10), file='C:\\MyDocuments\\test.csv')") Also, on a lesser note, if I create an object in R from java, is there any way to access it

Call R from Java using JRI, how to cast return value

ε祈祈猫儿з 提交于 2020-01-05 06:39:25
问题 I'm executing some R commands from Java using JRI.I want to use the results from R in my Java for further calculations but I have no idea how cast the returned object. call code in Java: REXP x; System.out.println(x = rengine.eval("source(\"/..../TS.R\")")); System.out.println( x.asVector().elementAt(0)); last line from R code: eq_all[length(eq_all)-1] -- output in Java console: [VECTOR ([REAL* (3.050462038715372)], [BOOLi* ])] [REAL* (3.050462038715372)] "3.050462038715372" is the right

How to set environment variables in Netbeans 8.0.2?

我的梦境 提交于 2020-01-03 11:28:40
问题 I'm running a test class that came with my JRI (Java-R interface) package. I'm running it through NetBeans. Unfortunately, NetBeans complains about R_HOME not being set. Creating Rengine (with arguments) Rengine created, waiting for R R_HOME is not set. Please set all required environment variables before running this program. Cannot load R Unable to start R How can I add the R_HOME environment variable in NetBeans? What I have tried: I defined R_HOME in .bash_profile and .bashrc. /Library

Trying to integrate R with my Java application using JRI, but I'm getting error. Can anyone explain the cause and solution?

◇◆丶佛笑我妖孽 提交于 2020-01-02 09:32:11
问题 I need to integrate Java with R to run some math commands and make plots using features of R. Following part of code is giving error. public static void main(String[] args){ HelloRWorld r = new HelloRWorld(); r.helloRWorld(); } public void helloRWorld() { // using rengine to connect to r rengine.eval(String.format("greeting <- '%s'", "Hello R World")); REXP result = rengine.eval("greeting"); System.out.println("Greeting from R: "+ result.asString()); } That's the error I'm getting and have no

Trying to integrate R with my Java application using JRI, but I'm getting error. Can anyone explain the cause and solution?

喜你入骨 提交于 2020-01-02 09:31:27
问题 I need to integrate Java with R to run some math commands and make plots using features of R. Following part of code is giving error. public static void main(String[] args){ HelloRWorld r = new HelloRWorld(); r.helloRWorld(); } public void helloRWorld() { // using rengine to connect to r rengine.eval(String.format("greeting <- '%s'", "Hello R World")); REXP result = rengine.eval("greeting"); System.out.println("Greeting from R: "+ result.asString()); } That's the error I'm getting and have no

In R, how to plot into a memory buffer instead of a file?

风格不统一 提交于 2019-12-28 22:03:43
问题 I'm using JRI to generate ggplot2 plots from Java. Currently I have to write plots to disk. How do I do this without going through files, i.e. just rendering the plots in memory? I tried using the Cairo package to plot to a textConnection, but that doesn't work without the "R Connections Patch," which after some Googling turns out to be ancient history. 回答1: Mostly from https://stat.ethz.ch/pipermail/r-devel/2010-August/058253.html. library(Cairo) library(png) library(ggplot2) Cairo(file='

In R, how to plot into a memory buffer instead of a file?

╄→尐↘猪︶ㄣ 提交于 2019-12-28 22:01:08
问题 I'm using JRI to generate ggplot2 plots from Java. Currently I have to write plots to disk. How do I do this without going through files, i.e. just rendering the plots in memory? I tried using the Cairo package to plot to a textConnection, but that doesn't work without the "R Connections Patch," which after some Googling turns out to be ancient history. 回答1: Mostly from https://stat.ethz.ch/pipermail/r-devel/2010-August/058253.html. library(Cairo) library(png) library(ggplot2) Cairo(file='

Converting REXP object to a double array (Java/R)

回眸只為那壹抹淺笑 提交于 2019-12-23 14:38:51
问题 I want R to produce, for example, normal data and then use this data in Java. I know there is a function to convert an REXP object to an array but it doesn't seem to work. Here is what I have: REXP x; x = re.eval("rnorm(100,50,10)"); double[] test = x.asDoubleArray(); System.out.println(x); System.out.println(test); I have printed both out to see what is wrong. The results are as follows: [REAL* (61.739814266023316, 40.25177570831545, 36.09450830843867, 48.06821029847672,...etc)] [D@61de33

How I can load a R script into JRI and execute from Java?

我怕爱的太早我们不能终老 提交于 2019-12-23 11:39:28
问题 I'm using JRI to execute R from Java and I saw that JRI use the eval() method to execute the R commands. I have one R script for execution. How I can load this script in JRI and execute it? 回答1: You can run an entire script with the R command source() 来源: https://stackoverflow.com/questions/8037411/how-i-can-load-a-r-script-into-jri-and-execute-from-java

Rengine.eval returns null

空扰寡人 提交于 2019-12-23 04:54:12
问题 I have the following implementation: public static void main(String[] args) { // new R-engine Rengine re = new Rengine(new String[] { "--vanilla" }, false, null); if (!re.waitForR()) { System.out.println("Unable to load R"); return; } else System.out.println("Connected to R"); re.eval("library(RMySQL)"); re.eval("library(xts)"); re.eval("library(forecast)"); re.eval("db = dbConnect(MySQL(), user='root', password='', dbname='stats_server', host='localhost')"); re.eval( "data = fetch