本家様 https://www.r-project.org/
言わずもがなの「R」
パッケージとして登録されているのでyumで気軽にインストールできる.
[root@centos7 ~]# yum info R-core
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* epel: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
Available Packages
Name : R-core
Arch : x86_64
Version : 3.6.0
Release : 1.el7
Size : 57 M
Repo : epel/x86_64
Summary : The minimal R components necessary for a functional runtime
URL : http://www.r-project.org
License : GPLv2+
Description : A language and environment for statistical computing and graphics.
: R is similar to the award-winning S system, which was developed at
: Bell Laboratories by John Chambers et al. It provides a wide
: variety of statistical and graphical techniques (linear and
: nonlinear modelling, statistical tests, time series analysis,
: classification, clustering, ...).
:
: R is designed as a true computer language with control-flow
: constructions for iteration and alternation, and it allows users
: to add additional functionality by defining new functions. For
: computationally intensive tasks, C, C++ and Fortran code can be
: linked and called at run time.
[root@centos7 ~]#
(インストールするなら下記を実行する)
yum install epel-release
yum install R-core R-core-devel
だがバージョンが「3.6.0」
より最新の「R」を使いたい場合は自らコンパイルする必要がある
下処理 †
yum groupinstall "Development Tools" "GNOME Desktop"
yum install readline-devel libXt-devel zlib-devel bzip2-devel xz-devel pcre2-devel libcurl-devel java-1.8.0-openjdk-devel libjpeg-turbo-devel libssh2-devel
(ubuntu20.04)
apt install build-essential
apt install gfortran libreadline-dev libz-dev libbz2-dev liblzma-dev libpcre2-dev libcurl4-openssl-dev libxt-dev
コンパイル †
[root@centos7 ~]# cd /apps/src
[root@centos7 src]# curl -O https://cran.r-project.org/src/base/R-4/R-4.1.0.tar.gz
[root@centos7 src]# tar cf R-4.1.0.tar.gz && cd R-4.1.0
[root@centos7 R-4.1.0]# ./configure --prefix=/apps/R-4.1.0 --enable-R-shlib
:
:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /apps/R-4.1.0
C compiler: gcc -std=gnu99 -g -O2
Fortran fixed-form compiler: gfortran -g -O2
Default C++ compiler: g++ -std=gnu++11 -g -O2
C++11 compiler: g++ -std=gnu++11 -g -O2
C++14 compiler:
C++17 compiler:
C++20 compiler:
Fortran free-form compiler: gfortran -g -O2
Obj-C compiler:
Interfaces supported: X11
External libraries: pcre2, readline, curl
Additional capabilities: NLS
Options enabled: shared R library, shared BLAS, R profiling
Capabilities skipped: PNG, JPEG, TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
[root@centos7 R-4.1.0]#
[root@centos7 R-4.1.0]# make && make check && make install
「make check」で「reg-packages.R」でのエラーが検出される. CentOS7の問題みたい..R-3.6.2(2019-12-12)から出てる様子
一応「R-4.1.0/tests/Makefile.common」から「reg-packages.R」を削除するとすんなり「make check」は通る.
Environment Modules †
「/etc/modulefiles/R/4.1.1」
#%Module1.0
set R /apps/R-4.1.1
prepend-path PATH $R/bin
setenv R_HOME_DIR $R
setenv R_LIBS_USER $env(HOME)/R/%V
dplyr †
> install.packages("dplyr")
library(dplyr) でエラー: ‘dplyr’ という名前のパッケージはありません
>
って言われた. dplyrパッケージを入れるにはOS提供のRであるならroot権限化で
> install.packages("dplyr")
RStudio Server †
本家様 https://www.rstudio.com/
ブラウザをインターフェースとしてRStudioを使えるようにします.
個別のwindows/macPCにRとRStudio(RStudio Desktop)を入れなくてもブラウザがあればRStudioが使える代物.
https://www.rstudio.com/products/rstudio/download-server/
に各プラットホームごとにインストール手順が参照できます
ここではCentOS7に入れてみますので、「RedHat/CentOS」を選びます
するとRStudio Serverパッケージのダウンロードとそのインストール方法が記載されています.
っでまず入手.
[root@centos7 ~]# wget https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-1.4.1717-x86_64.rpm
ダウンロードしたファイルは「rstudio-server-rhel-1.4.1717-x86_64.rpm」でサイズは63MBでした。
次にそれをインストールします
[root@centos7 ~]# yum localinstall rstudio-server-rhel-1.4.1717-x86_64.rpm
同時に「postgresql-libs」もインストールされます.
インストールと同時に「RStudio Server」が立ち上がろうとするのですが、起動しませんでした。
どうやら原因は「R」へのPATHが不正確であったため. yumでRをインストールしたら問題なかったのかも..
その際は「/etc/rstudio/rserver.conf」を修正します
[root@centos7 ~]# cat /etc/rstudio/rserver.conf
# Server Configuration File
rsession-which-r=/apps/R-4.1.0
[root@centos7 ~]# systemctl restart rstudio-server.service
っでブラウザでアクセスするのですが、どのポート?調べるには lsof とかを使う
[root@centos7 ~]# lsof -i
:
rserver 15575 rstudio-server 7u IPv4 122556 0t0 TCP *:msgsrvr (LISTEN)
[root@centos7 ~]#
[root@centos7 ~]# grep msgsrvr /etc/services
msgsrvr 8787/tcp # Message Server
msgsrvr 8787/udp # Message Server
[root@centos7 ~]#
とあるので 8787 となるが、firewallで閉じているのなら空ける
[root@centos7 ~]# firewall-cmd --add-port=8787/tcp --zone=public --permanent
[root@centos7 ~]# firewall-cmd --reload
そのアドレスにアクセスすると下記のような画面が表示される

OS内のユーザ(/etc/passwd)でログインしてみると下記のようにブラウザ内で RStudio が使えます

RStudio Desktop †
RStudio Serverの提供元から「RStudio Desktop」が提供されている。ライセンス品は非常に魅力的 https://www.rstudio.com/products/rstudio/download/
ここではFree版の「RStudio Desktop」を入手して使ってみます。
単純にパッケージを入手してインストールするだけ. ファイルは「rstudio-1.4.1717-x86_64.rpm」
[root@centos7 ~]# yum localinstall rstudio-1.4.1717-x86_64.rpm
(ubuntu)
wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-2022.02.0-443-amd64.deb
dpkg -i rstudio-2022.02.0-443-amd64.deb
にて完了
起動は
ただし、、windowsOSからCentOSにインストールした 「RStudio Desktop」を利用するには単にXを飛ばせばいいのですが、場合によっては何も映らない事がある
なら初めからwindowsOS版の「RStudio Desktop」を利用すればいいのだが、X越しに使ってみたい場合
その際は「~/.config/RStudio/desktop.ini」に下記を加える. 「~/.config/RStudio/desktop.ini」は「RStudio Desktop」(rstudio)を起動したときに作られる
[General]
cookies=@Invalid()
desktop.renderingEngine=software
*multi-user.targetではだめみたい. graphical.target で稼働が必要みたい
メモ †
8787ではなく80で使いたい場合
「/etc/rstudio/rserver.conf」に「www-port=80」を追記して「systemctl restart rstudio-server.service」を実施
firewallの再設定も忘れずに
install.packages("devtools",Ncpus=3)とすると3倍速くなる.
「libicui18n.so.58がない」とかでエラーが出る場合は anaconda がロードされているから.
anacondaにある「「libicui18n.so.58」をLD_LIBRARY_PATHとかで通せば行けるかもしれないが、、path環境からanacondaを抜いて作ったほうがいいかも.
export PATH=/apps/R-4.1.1/bin:/usr/bin:/usr/sbin
としてRを起動後「install.packages("devtools",Ncpus=3)」なら行ける