R のインストール
Windows, Mac, Linux(redhat, yellowdog, vine,...), Unix のインストールのコツなどを付け足してください。
最新版はこちらからダウンロードしてください。
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の新しい既定のパスを使いましょう。
最新版はこちらから、ダウンロードしてください。
http://aoki2.si.gunma-u.ac.jp/R/begin.html
Fink は、MacOSX用のパッケージ管理システムである。Fink をインストール後、
$ fink install r-base
とすることで、CLI 版 R がインストールできる。OSX 10.11~10.4まで対応している。
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 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 atlas
[+]cairo: use cairo and pango
debug: build with debug symbols
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
なお、R-appとR-frameworkにはvariantsはない。 Mac PortsはRのバージョンアップに追従してくれるので、Mac Portsで日頃からシステムをupgradeしていれば、いつでも最新バージョンのRがインストールされた状態になる。
※Mac Portsのバージョンが古いとインストールに失敗する場合があるので 以下のコマンドでMac Portsを最新化しておく。
$ sudo port selfupdate
MacOSXではデフォルトでバイナリのパッケージをインストールするようになっている。しかし、rgdal*1などバイナリを提供されていないパッケージが存在する。その場合は、ソースからインストールする。なお、Fink でバイナリ化されているものもある。
rgdalを例にとって説明する。
$ 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. [後略]インストールに失敗した
$ 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にインストールされている。
$ ./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 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)無事にインストールできた
(ADSL 等の比較的高速なインターネット接続可能状態にあることが大前提。)
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
apt-get update
apt-get install r-base
apt-get install r-cran-hmisc
| 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 |
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.
快適なダウンロードがお望みならCRAN国内ミラーの使い方を参照。
R-2.2.0 では,特に何にもしないで,
./configure make make install
で無事 make できるようになった
本家とは別にビルドされたマルチコア対応版R。比較的高速。
Windows版、MacOSX版あり。
REvolutionRは連邦の新型か参照
Linux の中には実行ファイルが用意されていないものがあります.その場合は Unix 版 R をインストールするのと同じ方法でソースからビルドするかと思います. 当方,VineLinux 4.2 を使っており,以下の手順でソースからのビルドを試みております.
$ 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++
$ ./configure $ make $ make install
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