LoginSignup
5
5

More than 5 years have passed since last update.

rsrubyをRailsで動かす

Last updated at Posted at 2014-07-01

RをRubyから使えるライブラリ、rsrubyをbundlerでインストールします。パッケージの管理はHomeBrewで行うものとします。

MacOSX10.6以前はX11が必須でしたが、今はXQuartzが必須になっているのでインストールします。

$ brew cask install xquartz
$ brew install homebrew/science/r
$ export R_HOME="/usr/local/Cellar/r/3.1.0/R.framework/Resources"
$ bundle config build.rsruby --with-R-dir=$R_HOME # コンパイルオプションを指定
$ bundle install --path=.bundle

で、終わりかと思ったらRailsで動かすにはR_HOMEを設定してやらないといけない。自分はMac上で開発しているので、とりあえず以下のコードでプラットフォームを判定している。

config/environment.rb
ENV['R_HOME'] ||= case RbConfig::CONFIG['host_os']
                  when /linux/; '/usr/local/lib64/R'
                  when /darwin/; '/usr/local/Cellar/r/3.1.1/R.framework/Resources'
                  end

そういえばRubyでプラットフォームを判定する時のデファクトっぽい書き方ってあるんだろうか。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5