LoginSignup
5
6

More than 5 years have passed since last update.

Rの2系をbrew installする

Posted at

Rのパッケージは、今のところ2系にしか対応していないものも多いため、3系だけだと困ることがある。
Rをbrew installすると3系がインストールされる。

$ brew update
$ brew install gfortran
$ brew tap homebrew/science
$ brew info R
R: stable 3.1.0, HEAD
http://www.r-project.org/
Not installed
From: https://github.com/homebrew/homebrew-science/commits/master/r.rb
(省略)

バージョンを変更してインストールするにはbrew versionsを使う。
インストール可能なバージョンを確認したら、対象のものをcheckoutする。

$ brew versions R
3.1.0    git checkout b81a08f r.rb
(省略)
2.15.3   git checkout 064c0db r.rb
(省略)
$ cd /usr/local/Library/Taps/homebrew/homebrew-science
$ git checkout 064c0db r.rb
$ brew info R
R: stable 2.15.3, HEAD
http://www.r-project.org
Not installed
From: https://github.com/homebrew/homebrew-science/commits/master/r.rb

これで2系のRをインストールできると思いきや、makeでエラーとなる。
R depends on gettext to fix build issue. #18198に書いてあるが、依存ライブラリのcairoがpkgconfigで指定されていないため。

これを参考に、23行目にdepends_on 'cairo'を追加する。

$ brew install R
$ sudo ln -s "/usr/local/opt/r/R.framework" /Library/Frameworks

OSXをLionやMountain LionからMarvericksにアップグレードしている場合、Rをインストールしようとするとエラーになる。
その場合は、一度gfortranと関連するライブラリをbrew uninstallしてから再インストールすると良い。

$ brew uninstall gmp mpfr libmpc cloog gfortran
$ brew install gfortran
$ brew install R
$ R

R version 2.15.3 (2013-03-01) -- "Security Blanket"
(省略)

インストールがうまく行ってもパッケージのインストールで失敗する場合もある。
自分の場合は、install.packages("knitr")で失敗した。
stackoverflowでも質問している人がいて、gettextをインストールすれば良いとのこと。
brew linkしたらWarningでたので、--forceつけて実行したらエラーが解消された。

$ brew install gettext
$ brew link gettext
Warning: gettext is keg-only and must be linked with --force
Note that doing so can interfere with building software.
$ brew link --force gettext

参考ページ

MacOSX に homebrew で R をインストール
Homebrew でバージョンを指定してインストールする
MacOSX に homebrew で R をインストール

5
6
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
6