Calling data
The following processing sketch ask R for 100 normal distributed randoms and then sort them. Then the data is fetched into an array of doubles and displayed in the draw method.
import org.rosuda.REngine.Rserve.*; import org.rosuda.REngine.*; double[] data; void setup() { size(300,300); try { RConnection c = new RConnection(); // generate 100 normal distributed random numbers and then sort them data= c.eval("sort(rnorm(100))").asDoubles(); } catch ( REXPMismatchException rme ) { rme.printStackTrace(); } catch ( REngineException ree ) { ree.printStackTrace(); } } void draw() { background(255); for( int i = 0; i < data.length; i++) { line( i * 3.0, height/2, i* 3.0, height/2 - (float)data[i] * 50 ); } }
See also:
sine-function experiment
projecting GIS Data on a sphere using Processing
processing ical-flowers-2.0
Training Bike Visualization
Can this work the other way i.e. have R call Processing as required? I'd like R to do some calculations and then call Processing for some more esoteric displays, but R has to initiate the call.
P.s.- I 'get' Matlab/R but am just a Java noob (hence Processing) and know nothing really about the 'serve' portion.
Very cool. Can you say anything more about getting R process up and running?
If I do this all manually, opening a terminal window, and starting R, and doing "library(Rserve", and "Rserve()", and THEN from within Processing run your program, all is well.
However, it appears that it is also possible to start Rserve from the command line using
R CMD Rserve
but when I did this, it told me that Rserve was not found:
noname:~ josh$ R CMD Rserve /Library/Frameworks/R.framework/Resources/bin/Rcmd: line 61: exec: Rserve: not found
Thanks!
Obedient bye, genial soul mate :)
This is really great, thanks! I plan on using/abusing this a ton.
hey there, I'm trying to use this basic tutorial to conect processing with R. I copied your code but got this error on Processing:
org.rosuda.REngine.Rserve.RserveException: Cannot connect: Connection refused at org.rosuda.REngine.Rserve.RConnection.
(RConnection.java:88)
any ideas on how to fix it?