The Comprehensive R Archive Network, CRAN
perlで言う所の CPAN かな. 必要な機能をネット経由でロードして新な機能を使うって感じ
Rを起動して、そのRプロンプト内で
install.packages("xxxx")として必要なパッケージを導入する.
っが、これがインターネットに繋がっていれば楽. そうでなく外に出れなく孤立した環境でCRANを使うにははて?どうすれば?
簡単には外部の公開されているCPANリポジトリサイトの中身を頂戴して、閉鎖ネット内にそのコンテンツが利用できるwebサイトを拵える.
外部にアクセス可能な所で必要なパッケージを取得して、閉鎖ネット内の計算機にコピーして運用もあるが、、正直面倒その上ない. そこパッケージには実がパッケージBが必要なんて、、そんなRPGゲームは避けたい
*外部に直接アクセスできる方は公開しているリソースを使いましょう. そっちの方が早いですから. ここはあくまでも閉鎖ネットでの運用を前提にしてます
大抵のサイトはrsyncで提供されているようなので、それを使ってミラーサイトを作り上げ、それを閉鎖ネットに運んでwebを立てる.
っでコンテンツ取得. *これが正しいかはよく分かりません *下記は動きません. 別のサイトを探すかhttpでミラーする必要アリです
[root@out ~]# cd /Public/mirror
[root@out mirror]# rsync -av --delete ftp.yz.yamagata-u.ac.jp::pub/cran/src/contrib/ ./cran/src/contrib/ --include="*.tar.gz" --include="PACKAGES*" --exclude="00Archive" --exclude="Archive" --exclude="Old"
[root@out mirror]# rsync -av --delete ftp.yz.yamagata-u.ac.jp::pub/cran/src/contrib/Symlink/ ./cran/src/contrib/Symlink/ --include="*.tar.gz" --exclude="*"「--exclude="*"」で全ての選択肢を外して「--include="*.tar.gz" 」で"*.tar.gz"なファイるだけを取得している
「00Archive」は取得していない. 「00Archive」を除いて 12GB ほどです
これで「/Public/mirror」にCRANが溜まる. PACKAGES と config.yaml が大事かな. 一連のコマンドを1つのshell scriptにして定期的に回すのがいいかな
そして溜まった「/Public/mirror」をUSB-HDD/SSDとかにrsyncでコピーして、閉鎖ネットに運び、これまたrsyncで閉鎖ネットwebサイトにコピーする.
っでこのコンテンツのある場所をhttpで(閉鎖ネット内に)公開(nfsで共有ができるか不明)
[root@c ~]# vi /etc/httpd/conf.d/cran.conf
Alias /src/contrib /Public/mirror/cran/src/contrib
<Directory "/Public/mirror/cran/src/contrib">
Options FollowSymLinks Indexes
AllowOverride none
Require all granted
</Directory>
[root@c ~]# systemctl reload httpd位置関係
http://ftp.yz.yamagata-u.ac.jp/pub/cran/src/
+index.html
+manuals.html
:
+bin/
+contrib/
+extra/
+main/ ----(ここをrsync)---> /Public/mirror/cran/src/contrib/
+A3_1.0.0.tar.gz そしてここを http://c.sybyl.local/src/contrib/ と写させる.
+AATtools_0.0.2.tar.gz
+ABACUS_1.0.0.tar.gz
:
+Symlink/外部に繋がった計算機でR実行後に「install.packages("xxxxxx") 」とパッケージのインストールを行うと
始めにどこの公開リポジトリを参照しますか?との問いが始まる
っが、ここは閉鎖ネット内なので、お外にはでれずに目的のパッケージは入らない.
なのでお外に出れない代わりに作った閉鎖ネット内のリポジトリを参照させる. 方法は R の中で定義するか、設定ファイルに書き込む
(Rの中で)
> install.packages("xxxxxx", repos="http://c.sybyl.local") *install.packagesコマンド内でリポジトリ先を指定する
(あるいはrepsを定義して)
> options(repos = structure(c(CRAN = "http://c.sybyl.local/"))) *変数reposにリポジトリ先を指定して
> getOption("repos") *変数reposの確認
CRAN
"http://c.sybyl.local/"
> install.packages("xxxxxxxx") *変数reposを利用してインストール
(設定ファイルなら)
illya@ubuntu:~$ echo "options(repos = structure(c(CRAN = 'http://c.sybyl.local/')))" >> $HOME/.Rprofile
(計算機全体にかける)
root@ubuntu:~# echo "options(repos = structure(c(CRAN = 'http://c.sybyl.local/')))" >> /apps/R-4.3.2/lib/R/etc/Rprofile.site計算機全体への適用はRのインストール先が「/apps/R-4.2.2」であったと仮定してのお話
環境変数に関してはRの中で「Sys.getenv()」を実行するといいかも.
リポジトリの設定が済んだらパッケージをインストールしてみます.
手始めに dplyr を入れます. 本家様 https://dplyr.tidyverse.org//
データの操作、集計がダントツで早い
> getOption("repos")
CRAN
"http://c.sybyl.local/"
> install.packages("dplyr")
> installed.packages()
> packageVersion("dplyr")
[1] ‘1.1.3’
>
> help(package=dplyr)
(Rに入っているirisデータを使ってちょいと出力)
> dplyr::slice(iris,1:5)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
>Rの外部パッケージは CRAN だけでなく Bioconductor(https://www.bioconductor.org/) のパッケージも利用します
Rのバージョン毎に適用可能なBioconductorのバージョンがある.
| Bioconductorのリリース日 | Bioconductor | Rのバージョン | 備考 |
| 2023.10.25 | 3.18 | 4.3.[2,3] | |
| 2023.4.26 | 3.17 | 4.3.[0,1] | |
| 2022.11.2 | 3.16 | 4.2.[2,3] | epel8/epel9で提供されるRは4.2.2 |
| 2022.4.27 | 3.15 | 4.2.[0,1] | |
| 2021.10.27 | 3.14 | 4.1.[2,3] | |
| 2021.5.20 | 3.13 | 4.1.[0,1] | |
| 2020.10.28 | 3.12 | 4.0.[3,4,5] | |
| 2020.4.28 | 3.11 | 4.0.[0,1,2] | |
| 2019.10.30 | 3.10 | 3.6.[2,3] | |
| 2019.3.3 | 3.9 | 3.6.[0,1] | epel7で提供されるRは 3.6.0 |
| 2018.10.31 | 3.8 | 3.5.[1,2,3] |
閉鎖ネット内では当然ながらBioconductorへのサイトに行けない. のでこちらもミラーサイトを作ります. ミラー作成方法は未公開
ここは R-4.3.2 を使っているのでbioconductorの 3.18 を取得します
「/Public/bioconductor/packages/3.18/{bioc,books,workflows}/src/contrib/」
「/Public/bioconductor/packages/3.18/data/{annotation,experiment}/src/contrib/」
っで取得したデータをwebで公開します
[root@c ~]# vi /etc/httpd/conf.d/bioconductor.conf
Alias /bioconductor /Public/bioconductor
<Directory "/Public/bioconductor">
Options FollowSymLinks Indexes
AllowOverride none
Require all granted
</Directory>
[root@c ~]# systemctl reload httpd
[root@c ~]# wget https://bioconductor.org/config.yaml -P /Public/bioconductor/な感じで
っで、「Rprofile.site」はこんな感じにします
root@ubuntu:~# vi /apps/R-4.3.2/lib/R/etc/Rprofile.site
options(repos = structure(c(CRAN = "http://c.sybyl.local/")))
options(BIOCONDUCTOR_CONFIG_FILE="http://c.sybyl.local/bioconductor/config.yaml")
options(BioC_mirror = "http://c.sybyl.local/bioconductor")
root@ubuntu:~#> install.packages("BiocManager")
Installing package into ‘/home/saber/.R/4.3.2’
(as ‘lib’ is unspecified)
trying URL 'http://c.sybyl.local/src/contrib/BiocManager_1.30.22.tar.gz' <-- CRANからBiocManagerを取得
Content type 'application/x-gzip' length 582690 bytes (569 KB)
:
:
> BiocManager::install("proActiv")
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
CRAN: http://c.sybyl.local/
Bioconductor version 3.18 (BiocManager 1.30.22), R 4.3.2 (2023-10-31)
:
trying URL 'http://c.sybyl.local/src/contrib/sys_3.4.2.tar.gz' <-- CRANも参照
:
trying URL 'http://c.sybyl.local/bioconductor/packages/3.18/bioc/src/contrib/zlibbioc_1.48.0.tar.gz' <-- bioconductorも参照
:
:
> library(proActiv)
Attaching package: ‘proActiv’
The following object is masked from ‘package:stats’:
filter
>R-4.3.2はBioconductor-3.18を参照なのでそれを準備してから
[root@centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@centos7 ~]# yum install libxml2-devel openssl-devel centos-release-scl-rh
[root@centos7 ~]# yum install devtoolset-9 <-- GCC-9を使います
[root@centos7 ~]# vi /apps/R-4.3.2/lib64/R/etc/Rprofile.site
options(repos = structure(c(CRAN = 'http://c.sybyl.local/')))
options(BIOCONDUCTOR_CONFIG_FILE="http://c.sybyl.local/bioconductor/config.yaml.3.18")
options(BioC_mirror = "http://c.sybyl.local/bioconductor")
[root@centos7 ~]#[saber@centos7 ~]$ source scl_source enable devtoolset-9 <-- GCC-9を有効にします. こうしないとコンパイルできないものがあるので.
[saber@centos7 ~]$ module use /apps/modulefiles/
[saber@centos7 ~]$ module load R/4.3.2
[saber@centos7 ~]$ R
> install.packages("BiocManager")
> BiocManager::install("ActiveDriverWGS")