1. 下载 安装 R
2. 下载安装 git
然后安装
3. 下载rsruby
git clone git://github.com/alexgutteridge/rsruby.git
设定 R_HOME 变量,在.profile 里面 export
export R_HOME=/Library/Frameworks/R.framework/Resources
cd rsruby/
ruby setup.rb config -- --with-R-dir=$R_HOME
ruby setup.rb setup
sudo ruby setup.rb install
4. 验证
require 'rsruby'
r = RSRuby.instance
# construct data to plot, graph of x vs sqrt(x)
xs = 10.times.collect {|i| i}
ys = xs.collect {|x| r.sqrt(x)}
r.png("example.png") # tell R we will create png file
r.plot(:x => xs,
:y => ys, # (x,y) coordinates to plot
:type=> "o", # draw a line through points
:col=> "blue", # colour the line blue
:main=> "Plot of x against sqrt(x)", # add title to graph
:xlab => "x", :ylab => "sqrt(x)") # add labels to axes
r.eval_R("dev.off()") # finish the plotting
liu-juns-macbook-pro:~ liujun$ irb
Ref:
1. http://github.com/alexgutteridge/rsruby
2. http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html
3. http://cran.r-project.org/bin/macosx/