「RSRubyReferenceManualChapter2」の編集履歴(バックアップ)一覧はこちら
RSRubyReferenceManualChapter2 - (2008/06/16 (月) 20:31:03) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
第2章
インストールと使い方
2.1 要求
第一に RSRuby をインストールする前に Ruby (http://www.ruby-lang.org/) が必要です。
RSRuby の現在のバージョンでは Ruby 1.8.4 だけでテストされていますが、1.8.x 系以前のバージョンでは動くでしょう。
また、動作確認済みの R 実行環境のも必要です。 R を --enable-R-shlib オプション付きでビルドすることで RSRuby は R の共有ライブラリとインタフェースを取れるようになります。
RSRuby の現在のバージョンでは R 2.2.1 だけでテストされていますが、以前のバージョンでも動くでしょう。
2.2 Installation
Installation requires some correct con?guring of your R setup and then a standard Ruby
extension install via setup.rb or rubygems.
1. First, ensure that the R_HOME environment variable is set correctly. On my Ubuntu
linux machine this is:
R_HOME=/usr/lib/R
While on OS X it is:
R_HOME=/Library/Frameworks/R.framework/Resources
2. Compile and install the Ruby library using setup.rb as shown. You need to supply
the location of your R installation for the libR shared library. This will usually be
the same as R_HOME.
cd rsruby
ruby setup.rb config -- --with-R-dir=/usr/lib/R
ruby setup.rb setup
sudo ruby setup.rb install
If you prefer to use rubygems then you just need to supply the location of the R
library to gem install:
7
gem install -- --with-R-dir=/usr/lib/R
If RSRuby does not compile you may need to con?gure the path to the R library.
Any one of the following should be su?cient (taken from the RPy documentation):
? make a link to R_HOME/bin/libR.so in /usr/local/lib or /usr/lib, then
run ldconfig,
? or, put the following line in your .bashrc (or equivalent):
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:R_HOME/bin
? or, edit the ?le /etc/ld.so.conf and add the following line:
R_HOME/bin
and then, run ldconfig.
3. Test it:
ruby setup.rb test
RSRuby should pass all tests.
You can avoid needing root in the install step by providing setup.rb with a suitable
install directory (such as home). Please run ruby setup.rb --help for more details.
2.3 Getting Started: A Small Example
RSRuby works ?ne with irb. A sample session is shown:
\$irb -rrsruby
irb> r = RSRuby.instance
=> #<RSRuby:0xb7cdec04>
require-ing rsruby loads the module, but unlike RPy it does not start the R in-
terpreter. Calling RSRuby.instance starts the R interpreter, a reference to which is
returned and stored in object r here. Since only one R interpreter can be running at
a time, RSRuby uses the standard library Singleton module. This replaces RSRuby.new
with RSRuby.instance. further calls to RSRuby.instance return the original interpreter
object.
Calls to R functions are made via the R interpreter object. In the example below the
R function wilcox.test is called with two Ruby Arrays as arguments. These Arrays are
converted to R by RSRuby. The list returned from the R method is converted to a Ruby
Hash. Details of the conversion procedure can be found in Chapter 4.
irb> r.wilcox_test([1,2,3],[4,5,6])
=> {"p.value"=>0.1, "null.value"=>{"mu"=>0.0},
"data.name"=>"c(1, 2, 3) and c(4, 5, 6)",
"method"=>"Wilcoxon rank sum test",
"alternative"=>"two.sided", "parameter"=>nil,
"statistic"=>{"W"=>0.0}}
表示オプション
横に並べて表示:
変化行の前後のみ表示: