Hello World from OSS Silicon Valley


HowToUse/RubyOnRails/4.2/Rserve/3.2

_ Prerequisite

_ Install&Setup

Step.1
Install Rserve in R.
> install.packages("Rserve")
Step.2
Launch Rserve
$ R CMD RServe

When you use rvm for ruby version management, RServe can't be found with the above command line. In that case, execute the following command, and specify the path to RServe.

$ sudo find / -name Rserve
$ R CMD <RServe Path>

(Example)

$ R CMD ~/R/x86_64-pc-linux-gnu-library/3.2/Rserve/libs/Rserve

_ HowToUse

_ Connect Rails with Rserve

Step.1
Prepare rails project.
Step.2
Add rserve-client in Gemfile
gem 'rserve-client', require:'rserve'
$ bundle install
Step.3
Edit code as below.
c = Rserve::Connection.new
...
c.assign("root", Rails.root.to_s)
...
c.eval <<-EOF
  x = rnorm(100,0,1)
  png(paste(root, "/app/assets/images/test.png", sep=""))
  hist(x)
  dev.off()
EOF

Then your rails application can connect with Rserve.

_ Author

S.Yatsuzuka

Last-modified: 2015-12-26 (Sat) 05:05:02 (3036d)