Hello World from OSS Silicon Valley


HowToUse/RubyOnRails/4.2/Rserve/3.2


_ Prerequisite

  • xxx installation (You can refer Overall/xxx)

_ Install&Setup

Step.1
xxx

_ HowToUse

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
Step.3
Add rserve-client in Gemfile
gem 'rserve-client', require:'rserve'
$ bundle install
Step.4
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

_ Author

S.Yatsuzuka