R のインストール

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



CRANにproxy環境で接続

R4.2.0で接続方法変わりました。アップデートしたら接続できなくなったという場合は Windowsの例として

setx HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.example.com:PORT_NUM

のようにして環境変数に設定しておくとうまくいきました。

Windows 版 R のインストール

最新版はこちらからダウンロードしてください。

Windows Vista での問題点

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の新しい既定のパスを使いましょう。

参考リンク

Mac 版 R のインストール

Mac OSX

最新版はこちらから、ダウンロードしてください。

参考リンク

http://aoki2.si.gunma-u.ac.jp/R/begin.html

Fink 版 R のインストール

Fink は、MacOSX用のパッケージ管理システムである。Fink をインストール後、

$ fink install r-base

とすることで、CLI 版 R がインストールできる。OSX 10.13~10.4まで対応している。

Finkで提供しているCRANパッケージ一覧

Mac Ports 版 R のインストール

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を例にとって説明する。

  1. CRANからrgdalのソースファイル(例えば、rgdal_0.6-28.tar.gz)をダウンロードする
  2. rgdalが依存するライブラリ(gdalとproj)をあらかじめインストール
    • MacPortsを使っている場合、次のようにしてインストールする
      $ sudo port install gdal proj
  3. とりあえずインストールを試みる。ソースファイルがあるディレクトリで次のコマンドを実行する
    $ 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.
    [後略]
    インストールに失敗した
  4. エラーから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にインストールされている。
  5. 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=をつければよいことがわかる。
  6. 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=で指定すればよいと書いてある。
  7. オプションをつけて再度インストール
    $ 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 のインストール

Debian GNU/Linux (含む Knoppix)の場合 (インターネット経由でオリジナル版をインストールする場合)

(ADSL 等の比較的高速なインターネット接続可能状態にあることが大前提。)

r-baser-cran-codar-cran-lmtestr-cran-rcmdr
r-cran-vrr-noncran-lindseyr-base-corer-cran-dbi
r-cran-mapdatar-cran-rmysqlr-cran-xmlr-nonlinear
r-base-devr-cran-designr-cran-mapprojr-cran-rodbc
r-doc-htmlr-omegahat-ggobir-base-htmlr-cran-effects
r-cran-mapsr-cran-rpartr-doc-infor-omegahat-rgtk
r-base-latexr-cran-foreignr-cran-mcmcpackr-cran-rquantlib
r-doc-pdfr-pdlr-cran-abindr-cran-gtkdevice
r-cran-mgcvr-cran-statdatamlr-gnomer-recommended
r-cran-bootr-cran-hmiscr-cran-mysqlr-cran-survival
r-mathlibr-xmlr-cran-carr-cran-kernsmooth
r-cran-nlmer-cran-tkrplotr-noncran-designr-cran-cluster
r-cran-latticer-cran-qtlr-cran-tseriesr-noncran-hmisc

openSUSE10.2 Linux 版インストール

Ubuntu Linux の場合:

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 のインストール

ソースからのコンパイル法 (含む Linux)

山本HP

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

R-2.2.0 では,特に何にもしないで,

./configure
make
make install

で無事 make できるようになった

REvolutionR(IntelMKL版R:マルチコア対応:Windows,MacOSX)

本家とは別にビルドされたマルチコア対応版R。比較的高速。
Windows版、MacOSX版あり。
REvolutionRは連邦の新型か参照

Microsoft R Open

最新版はこちらからダウンロードしてください。

Linuxでソースからのビルド(VineLinuxを例として)

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

パッケージのインストール

ネットにつながった、自分が管理するコンピューターに、CRANやミラーサイトからインストールする場合

1. install.packages("パッケージ名") で簡単にインストールできる。

2. インストールしおえたら library(パッケージ名) でロードして使用可能になる。

上記以外で、圧縮パッケージだけは入手できた場合

1. まず .libPaths() でパッケージを入れるべきlibraryフォルダを確認。そこにパッケージを解凍する。

2. library() コマンドでインストールはできたことを確認。(これは省略可。より詳しいコマンドとして installed.packages() もある。)

3. library(パッケージ名) でロード(読み込み)する。エラーが出なければパッケージを使用可能。 (注:ロードはRを起動するたびに行わないといけない。そのパッケージを使う.Rスクリプトの先頭に library(パッケージ名) の一行を入れておくとよい。)

興味のある分野のパッケージを丸ごとインストールする

CRAN Task View


*1 現在はバイナリが提供されており、CRAN になくても、CRAN Extra で提供されているものもある

添付ファイル: filewin-03.png 4765件 [詳細] filewin-04.png 4676件 [詳細] filewin-02.png 4482件 [詳細] filewin-01.png 1237件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-25 (土) 11:19:16