Transfer files through Rserve

August 4, 2009
By

(This article was first published on Romain Francois, Professional R Enthusiast, and kindly contributed to R-bloggers)

This post is motivated by this question on R-help. This is a simple java class that sends files through Rserve using the classes RFileInputStream and RFileOutputStream

Then we create a simple file on the client machine:

$ cat > testfile.txt
bla bla
^C

And we are good to go:

$ javac -cp .:REngine.jar:Rserve.jar RserveWire.java
$ java -cp .:REngine.jar:Rserve.jar RserveWire testfile.txt serverfile.txt
/tmp/Rserv/conn6
writing the client file 'testfile.txt' to the server as 'serverfile.txt'
writing the server file 'file.txt' to the client as 'file.txt' 

Now in the directory /tmp/Rserv/conn6 of the server, there are the files "serverfile.txt" and "file.txt"

$ cat serverfile.txt 
bla bla
$ cat file.txt
 [1] -1.16541741 -0.55857285  2.19752036 -0.78432188  1.40739981 -0.87252966
 [7] -0.11545651 -0.36735874 -2.75736666  0.29798096 -0.86836355 -0.03416198
[13] -0.44344089  0.88976360  0.58821334 -0.10354205 -0.88760475 -0.64608338
[19]  0.96552319 -1.57166441 -0.19010633 -1.42239696  0.49363257  0.06167547
[25]  0.34801546 -0.41211734 -0.20320050 -1.45370497  1.34383425 -0.89461504

and on the client there is also the "file.txt"

$ cat file.txt
 [1] -1.16541741 -0.55857285  2.19752036 -0.78432188  1.40739981 -0.87252966
 [7] -0.11545651 -0.36735874 -2.75736666  0.29798096 -0.86836355 -0.03416198
[13] -0.44344089  0.88976360  0.58821334 -0.10354205 -0.88760475 -0.64608338
[19]  0.96552319 -1.57166441 -0.19010633 -1.42239696  0.49363257  0.06167547
[25]  0.34801546 -0.41211734 -0.20320050 -1.45370497  1.34383425 -0.89461504

To leave a comment for the author, please follow the link and comment on his blog: Romain Francois, Professional R Enthusiast.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.