COLOR(red){SIZE(25){R のインストール}}

Windows, Mac, Linux(redhat, yellowdog, vine,...), Unix のインストールのコツなどを付け足してください。
----
#contents
----

* Windows 版 R のインストール [#p7074c04]

最新版は[[こちら:http://cran.ism.ac.jp/bin/windows/]]からダウンロードしてください。

** Windows Vista での問題点 [#h4666b84]

Vistaにインストールして動かないと嘆いている方はここを読んでください。
http://cran.r-project.org/bin/windows/rw-FAQ.html#Does-R-run-under-Windows-Vista_003f

Vista (に限らず2000,XPでも同種の障害が生じ得ます) では、昔ながらのパス、例えば
 C:\Documents and Settings\<USERNAME>\My Documents
以下に本体をインストールしたり、ユーザのライブラリパスを設定したりすると、まともに動きません(たとえ英数字だけのパスであっても)。
素直に、Vistaの新しい既定のパスを使いましょう。

** 参考リンク [#v33ca538]
-[[Installing R packages without admin rights on MS Windows:http://lamages.blogspot.jp/2012/04/installing-r-packages-without-admin.html]]

* Mac 版 R のインストール [#xb827720]

**[[Mac OSX:http://cran.ism.ac.jp/bin/macosx/]]  [#f6085c3f]

最新版は[[こちら:http://cran.ism.ac.jp/bin/macosx]]から、ダウンロードしてください。

** 参考リンク [#kb583159]
http://aoki2.si.gunma-u.ac.jp/R/begin.html

** Fink 版 R のインストール [#f098cc2d]
Fink は、MacOSX用のパッケージ管理システムである。Fink をインストール後、
 $ fink install r-base
とすることで、CLI 版 R がインストールできる。10.9~10.4まで対応している。
- パッケージは、CRAN からも Fink からもインストールできる。CRAN パッケージは、cran-packagename-r31 のような名称で、200以上ある。CRAN からインストールされたパッケージはユーザーディレクトリに格納される。Fink でインストールされたパッケージは /sw/lib/R/site-library/ に格納される。両者は別々に管理されるため、Fink 以外の R との併用が可能。
- QGIS からは qgis-plugin-manager をインストールすることにより、R を呼び出すことができる。QGIS と R が統合されているのは、MacOSX では Fink 版のみ。
- GUI としては、X11ベースのRコマンダーと RStudio (rstudio-desktop) が使用できる。
- Fink は日本人が多い。R のメンテナ(Fink のメンテナであり、R の開発者ではない)も日本人である。バグ報告などが日本語でできる。

[http://pdb.finkproject.org/pdb/browse.php?summary=cran Finkで提供しているCRANパッケージ一覧]

** Mac Ports 版 R のインストール [#f098cc2d]
Mac Ports は、MacOSX用のパッケージ管理システムである。
Mac Portsでは3種類のRのPort (R, R-app, R-framework)が用意されている。
 $ sudo port install R
とすることで、CLI 版 R がインストールできる。このシステムの特徴は、
variantとよばれるオプションの指定が可能で、cranで配布されるバイナリとはひと味違う。
用意されているvariantsは下記の通り。
 R has the variants:
 [+]accelerate: build using the BLAS and Lapack in Apple's Accelerate framework
      * conflicts with builtin_lapack
    accelerate: build using the BLAS and Lapack in Apple's Accelerate framework
      * conflicts with atlas builtin_lapack
    atlas: build using the BLAS in the atlas port
      * conflicts with accelerate builtin_lapack
    builtin_lapack: build using reference BLAS and Lapack
      * conflicts with accelerate
 [+]cairo: include cairo support in R's x11 graphics device
      * requires x11
 [+]builtin_lapack: build using reference BLAS and Lapack
      * conflicts with accelerate atlas
 [+]cairo: use cairo and pango
    debug: build with debug symbols
    gfortran45: build with gfortran from gcc45
      * conflicts with gfortran46 gfortran47 gfortran48 gfortran49
    gfortran46: build with gfortran from gcc46
      * conflicts with gfortran45 gfortran47 gfortran48 gfortran49
    gfortran47: build with gfortran from gcc47
      * conflicts with gfortran45 gfortran46 gfortran48 gfortran49
 [+]gfortran48: build with gfortran from gcc48
      * conflicts with gfortran45 gfortran46 gfortran47 gfortran49
    gfortran49: build with gfortran from gcc49
      * conflicts with gfortran45 gfortran46 gfortran47 gfortran48
    dragonegg33: Build using the MacPorts dragonegg 3.3 compiler
      * conflicts with dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    dragonegg34: Build using the MacPorts dragonegg 3.4 compiler
      * conflicts with dragonegg33 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    g95: Build using the g95 Fortran compiler
      * conflicts with dragonegg33 dragonegg34 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    gcc44: Build using the MacPorts gcc 4.4 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    gcc45: Build using the MacPorts gcc 4.5 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    gcc46: Build using the MacPorts gcc 4.6 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc47 gcc48 gcc49 gcc5 gcc6 gcc7
    gcc47: Build using the MacPorts gcc 4.7 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc48 gcc49 gcc5 gcc6 gcc7
    gcc48: Build using the MacPorts gcc 4.8 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc49 gcc5 gcc6 gcc7
    gcc49: Build using the MacPorts gcc 4.9 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc5 gcc6 gcc7
    gcc5: Build using the MacPorts gcc 5 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc6 gcc7
 [+]gcc6: Build using the MacPorts gcc 6 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc7
    gcc7: Build using the MacPorts gcc 7 compiler
      * conflicts with dragonegg33 dragonegg34 g95 gcc44 gcc45 gcc46 gcc47 gcc48  gcc49 gcc5 gcc6
 [+]recommended: install recommended R packages
    tcltk: enable use of tcltk
      * requires x11
    tests: include tests of R installation
 [+]x11: enable use of x11
 [+] x11: enable use of x11

なお、R-appとR-frameworkにはvariantsはない。
Mac PortsはRのバージョンアップに追従してくれるので、Mac Portsで日頃からシステムをupgradeしていれば、いつでも最新バージョンのRがインストールされた状態になる。

※Mac Portsのバージョンが古いとインストールに失敗する場合があるので
以下のコマンドでMac Portsを最新化しておく。
 $ sudo port selfupdate


** バイナリの提供されていないないパッケージ [#ga3d6e58]
MacOSXではデフォルトでバイナリのパッケージをインストールするようになっている。しかし、rgdal((現在はバイナリが提供されており、CRAN になくても、CRAN Extra で提供されているものもある))などバイナリを提供されていないパッケージが存在する。その場合は、ソースからインストールする。なお、Fink でバイナリ化されているものもある。

rgdalを例にとって説明する。
+ CRANからrgdalのソースファイル(例えば、rgdal_0.6-28.tar.gz)をダウンロードする
+ rgdalが依存するライブラリ(gdalとproj)をあらかじめインストール
-- MacPortsを使っている場合、次のようにしてインストールする
 $ sudo port install gdal proj
+ とりあえずインストールを試みる。ソースファイルがあるディレクトリで次のコマンドを実行する
 $ sudo R CMD INSTALL rgdal_0.6-28.tar.gz
 * installing to library ‘/Library/Frameworks/R.framework/Resources/library’
 * installing *source* package ‘rgdal’ ...
 gdal-config: gdal-config
 [中略]
 checking for proj_api.h... yes
 checking for pj_init_plus in -lproj... no
 Error: libproj.a not found.
 [後略]
インストールに失敗した
+ エラーからprojライブラリのインストール先が見つからないと判断し、インストール先を把握する
-- MacPortsの場合、インストール先は次のようにして確認できる
 $ port contents proj
 Port proj contains:
  /opt/local/bin/cs2cs
  /opt/local/bin/geod
 [中略]
  /opt/local/include/nad_list.h
  /opt/local/include/org_proj4_Projections.h
  /opt/local/include/proj_api.h
  /opt/local/include/projects.h
  /opt/local/lib/libproj.0.6.6.dylib
 [後略]
projライブラリのインストール先は/opt/local/libであることがわかる。projの開発ファイルは/opt/local/includeにインストールされている。
+ rgdalのtar.gzを展開し、./configure --helpを実行してオプションを把握する
 $ ./configure --help
 [中略]
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-gdal-config=GDAL_CONFIG
                           the location of gdal-config
   --with-proj-include=INCLUDE_PATH
                           the location of proj header files
   --with-proj-lib=LIB_PATH
                           the location of proj libraries
projライブラリのインストール先を指定するには、には--with-proj-lib=をつければよいことがわかる。
+ Rのインストールの時にどうすればconfigureのオプションを設定できるのかヘルプを参照する
 $ R CMD INSTALL --help
 Usage: R CMD INSTALL [options] pkgs
 [中略]
 for Unix
      --configure-args=ARGS
                        set arguments for the configure scripts (if any)
      --configure-vars=VARS
                        set variables for the configure scripts (if any)
      --libs-only       only install the libs directory
      --no-multiarch    build only the main architecture
 [後略]
ヘルプによると--configure-args=で指定すればよいと書いてある。
+ オプションをつけて再度インストール
 $ sudo R CMD INSTALL rgdal_0.6-28.tar.gz --configure-args='--with-proj-lib=/opt/local/lib'
 * installing to library ‘/Library/Frameworks/R.framework/Resources/library’
 * installing *source* package ‘rgdal’ ...
 gdal-config: gdal-config
 checking for gcc... gcc -arch x86_64 -std=gnu99
 [中略]
 * DONE (rgdal)
無事にインストールできた



* Linux 版 R のインストール [#if8c08b4]
** Debian GNU/Linux (含む Knoppix)の場合 (インターネット経由でオリジナル版をインストールする場合) [#td663091]
(ADSL 等の比較的高速なインターネット接続可能状態にあることが大前提。)
- root になる
- エディタで /etc/apt/source.list に次の行を付け加える(最新版の場合)。
  deb ftp://ftp.jp.debian.org/debian-jp stable-jp main contrib
  deb ftp://ftp.jp.debian.org/debian-jp testing-jp main contrib
  deb ftp://ftp.jp.debian.org/debian-jp unstable-jp main contrib
- Debian パッケージリスト更新命令を実行
  apt-get update
- 次の命令を実行。自動的に関連基本パッケージ(数値ライブラリ等も含み)が同時にインストールされ、直ちに R が使えるようになる
  apt-get install r-base
- 関連パッケージは同様にインストール。例えば
  apt-get install r-cran-hmisc
- バージョンアップは同様の手順でできる。古いものを削除する必要は無く、既に最新バージョンなら何も行なわれない。
- Knoppix(-jp) の場合基本メニューにある Debian パッケージ管理ソフト KPackage を起動するとメニュー方式で個別にインストールできわかりやすい
- ちなみに現時点での Debian.org にある R 関連のパッケージは次の通り(もちろんこれらのうちアドオンパッケージは R をインストール後、R 経由で CRAN から(最新版を)インストールすることができる)

|r-base |             r-cran-coda |       r-cran-lmtest|      r-cran-rcmdr |
|r-cran-vr|          r-noncran-lindsey|r-base-core  |      r-cran-dbi |
|     r-cran-mapdata|     r-cran-rmysql  |    r-cran-xml  |   r-nonlinear|
|r-base-dev |        r-cran-design |     r-cran-mapproj |    r-cran-rodbc  |
|r-doc-html     |    r-omegahat-ggobi |r-base-html  |      r-cran-effects |
|    r-cran-maps   |     r-cran-rpart |      r-doc-info|   r-omegahat-rgtk|
|r-base-latex  |     r-cran-foreign |    r-cran-mcmcpack |   r-cran-rquantlib|
|   r-doc-pdf |         r-pdl|r-cran-abind   |    r-cran-gtkdevice|
|   r-cran-mgcv |       r-cran-statdataml|  r-gnome |           r-recommended|
|r-cran-boot |       r-cran-hmisc |      r-cran-mysql  |     r-cran-survival|
|    r-mathlib |         r-xml |r-cran-car|         r-cran-kernsmooth|
|  r-cran-nlme |       r-cran-tkrplot|     r-noncran-design|r-cran-cluster|
|     r-cran-lattice |    r-cran-qtl  |       r-cran-tseries| r-noncran-hmisc|

** openSUSE10.2 Linux 版インストール [#xb9b1224]

-YaST2を立ち上げインストールソースの変更を行う。
-追加ボタンでhttpを選択。サーバー名に
software.opensuse.org/download/science/openSUSE_10.2/を入力
-改めてソフトウエア管理からインストールする。
-たぶん他のバージョンやyumを用いて/etc/yum.repos.dの変更でもできると思います。
やってませんが。
-CRANミラーでのSuSE用r-baseのアップが遅いのですが、こちらのリポジトリにしっかりアップされていました。
-suse10.3の場合、リポジトリをsoftware.opensuse.org/download/science/openSUSE_10.3/とすればできました。

** Ubuntu Linux の場合: [#pbac840c]
Ubuntu Linux 版のRのインストールと関連パッケージのインストールについては CRAN (のミラー)にある次の文章を参考にしてください。一度インストールすると、本体および各パッケージのバージョンアップがあると更新の注意が自動的に表示されますから、常に最新の状態にしておくことが容易です。ただし、Ubuntu Linux 自体のバージョンアップがありますのでこれは自動ではできない(?)。古いバージョンでも関連ソフトは数年間はメンテナンスがされるようです。要点をまとめておきます。いずれも端末からコマンドを入力して実行します。なお、Ubuntu にはルートモードが無く(?)、ルート権限で実行するにはコマンドの前に sudo 命令を付け加えます。 ※追記 Ubuntuのバージョンによっては(4)の手順のみで問題ない

 (1) /etc/apt/sources.list ファイルをルート権限で編集
   (ルートパスワードの入力が求められます)
  ここでは既定のエディター gedit を使います。 
  
  $ sudo gedit /etc/apt/sources.list  
 
 (2) 使用中の Ubuntu のバージョンに応じてつぎのような一行を付け加える。
     (統計数理研究所のミラーを使う)
 
  deb http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu hardy/
  deb http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu gutsy/
  deb http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu feisty/
  deb http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu dapper/
  deb http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu natty/
 
 (3) Ubuntu レポジトリの公開鍵を入手
 
  $ gpg --keyserver subkeys.pgp.net --recv-key E2A11821
  $ gpg -a --export E2A11821 | sudo apt-key add -
 (http://cran.md.tsukuba.ac.jp/bin/linux/ubuntu/READMEによると、2011年9月26日現在は以下のようなコマンドのようです。)
  $ gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
  $ gpg -a --export E084DAB9 | sudo apt-key add -
  
 (4) R 本体と Ubuntu に用意されているパッケージのインストール
    (システムにインストールするためやはりルート権限で実行)
    (r-base-dev をインストールするとCやFortranがインストールされます)
  $ sudo apt-get update
  $ sudo apt-get install r-base
  $ sudo apt-get install r-base-dev
  $ sudo apt-get install r-cran-*
 
 (5) Ubuntu に用意されていないパッケージ xxx はCRANからxxx.tar.gz ファイルを
     ダウンロードし以下の命令を端末で実行
  $ sudo R CMD INSTALL xxx.tar.gz
   
 UBUNTU PACKAGES FOR R
 
 R packages for Ubuntu on i386 and amd64 are available for all stable Desktop   
 releases of Ubuntu until their official end of life date. As of April 2008, 
 these are Hardy Heron (8.04), Gutsy Gibbon (7.10), Feisty Fawn (7.04) and Dapper  
 Drake (6.06). See https://wiki.ubuntu.com/Releases for details.
 INSTALLATION
 
 To obtain the latest R packages, add an entry like
 
    deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu hardy/
 
 or
 
    deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu gutsy/
 
 or
 
    deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu feisty/
 
 or
 
    deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu dapper/
 
 in your /etc/apt/sources.list file. See http://cran.r-project.org/mirrors.html 
 for the list of CRAN mirrors. To install the complete R system, use
 
    sudo apt-get update
    sudo apt-get install r-base
 
 Users who need to compile packages should also install the r-base-dev package:
 
    sudo apt-get install r-base-dev
 
 The R packages for Ubuntu should otherwise behave like the Debian ones. For more 
 information, see the README file in http://cran.R-project.org/bin/linux/debian/
 SUPPORTED PACKAGES
 
 A number of R packages are available from the Ubuntu repositories with names  
 starting with r-cran-. Note, however, that only the packages part of the  
 r-recommended bundle are kept up-to-date on CRAN. Currently, these are:
 
    r-cran-boot
    r-cran-cluster
    r-cran-codetools
    r-cran-foreign
    r-cran-kernsmooth
    r-cran-lattice
    r-cran-mgcv
    r-cran-nlme
    r-cran-rpart
    r-cran-survival
    r-cran-vr
 
 The other r-cran-* packages are updated with Ubuntu releases only.
 
 Because they rely on the installed version of R, we also provide, on an  
 experimental basis, up-to-date versions of the following packages:
 
    littler
    rkward
    python-rpy     (not on Dapper)
    python-rpy-doc (not on Dapper)
 
 Please notice that the maintainers are not necessarily users of these packages  
 themselves, so positive and negative feedback through the usual channels (see 
 below) would be appreciated.
 SECURE APT
 
 The Ubuntu archives on CRAN are signed with the key of "Vincent Goulet  
 <vincent.goulet@act.ulaval.ca>" with key ID E2A11821. You can fetch this key 
 with
 
    gpg --keyserver subkeys.pgp.net --recv-key E2A11821
 
 and then feed it to apt-key with
 
    gpg -a --export E2A11821 | sudo apt-key add -
 
 Some people have reported difficulties using this approach. The issue was usually 
 related to a firewall blocking port 11371. An alternative approach is to search 
 for the key at http://keyserver.noreply.org/ and copy the key to a plain text 
 file, say key.txt. Then, feed the key to apt-key with
 
    sudo apt-key add key.txt
 
 ADMINISTRATION AND MAINTENANCE OF R PACKAGES
 
 The R packages part of the Ubuntu r-base and r-recommended packages are installed 
 into the directory /usr/lib/R/library. These can be updated using apt-get with
 
    sudo apt-get update
    sudo apt-get upgrade
 
 The other r-cran-* packages shipped with Ubuntu are installed into the directory 
 /usr/lib/R/site-library.
 
 Installing R packages not provided with Ubuntu first requires tools to compile 
 the packages from source. These tools are installed via the R development package 
 with
 
    sudo apt-get install r-base-dev
 
 Then a site administrator can install R packages into the directory  
 /usr/local/lib/R/site-library by running R as root and using the
 
    > install.packages()
 
 function. A routine update can then be undertaken from R using
 
    > update.packages(lib.loc = "/usr/local/lib/R/site-library")
 
 Individual users can install R packages into their home directory. The simplest 
 procedure is to create a file ~/.Renviron containing, e.g.,
 
    R_LIBS="~/lib/R/library:${R_LIBS}"
 
 The install.packages() and update.packages() functions will then work in directory
 ~/lib/R/library.
 
* Unix 版 R のインストール [#h726f629]

** ソースからのコンパイル法 (含む Linux) [#gea6368d]
[[山本HP:http://stat.sm.u-tokai.ac.jp/~yama/R/install.html]]

快適なダウンロードがお望みなら[[CRAN国内ミラーの使い方]]を参照。

R-2.2.0 では,特に何にもしないで,
 ./configure
 make
 make install
で無事 make できるようになった

*REvolutionR(IntelMKL版R:マルチコア対応:Windows,MacOSX) [#e67e6cb8]
本家とは別にビルドされたマルチコア対応版R。比較的高速。~
Windows版、MacOSX版あり。~
[[REvolutionRは連邦の新型か]]参照

*Linuxでソースからのビルド(VineLinuxを例として) [#e326bf4a]

Linux の中には実行ファイルが用意されていないものがあります.その場合は Unix 版 R をインストールするのと同じ方法でソースからビルドするかと思います.
当方,VineLinux 4.2 を使っており,以下の手順でソースからのビルドを試みております.

- ルート権限になった後,下記サイトから R-2.8.1.tar.gz をダウンロードする.
[[http://cran.md.tsukuba.ac.jp/src/base/R-2/R-2.8.1.tar.gz:http://cran.md.tsukuba.ac.jp/src/base/R-2/R-2.8.1.tar.gz]]
-「R HOME」というディレクトリを作成した後,ここで R-2.8.1.tar.gz を解凍(untar)する.
-Linux 環境によっては「f77(g77で代替化)」「readline(もしくはreadline4)」「gcc」「c++」がない場合があるので,これらのパッケージを事前にインストールする.例えば,「g77」「c++」をインストールする場合は,ルート権限になった後,以下のコマンドを実行してパッケージをインストールする.

 $ apt-get update
 $ apt-get install gcc-g77
 $ apt-get install readline
 $ apt-get install readline4
 $ apt-get install gcc
 $ apt-get install gcc-c++

- kterm 上で「R HOME」に移動し、下記コマンドを実行する。

 $ ./configure
 $ make
 $ make install

- 「./configure」実行時に以下のエラーが出る場合がある.

 configure: error: --with-readline=yes (default) and headers/libs are not available
 configure: error: --with-x=yes (default) and X11 headers/libs are not available 

その場合は,「./configure」にオプションを付けると無理やりインストールすることが出来るが・・・.

 ./configure --with-readline=no --with-x=no 

あまり望ましくないので、エラーが出た場合はconfig.logの中身を確認して足りないライブラリやヘッダを調査してインストールした上で./configureを実行すること。
(足らないライブラリとしてはXOrg-devel libpng-devel pcre-devel libjpeg-devel readline-devel ncurses-devel bzip2-devel zlib-devel などが候補に挙がる)
apt-cache search XXX 等を実行して、足らないパッケージを探すこと。
ちなみに、XOrg-develとreadline-develが足りなかった場合は、以下の命令を実行する。

 $ apt-get install XOrg-devel
 $ apt-get install readline-devel

* 興味のある分野のパッケージを丸ごとインストールする [#k5f6997c]
[[CRAN Task View]]


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS