Install R on mac OSX

1. 下載 安裝 R

R-2.10.1.pkg

 

 

 

2. 下載安裝 git

git-1.6.6.1-intel-leopard.dmg

然後安裝

 

 

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

 


5. 輸出的圖片 


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/

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章