LoginSignup
5
3

More than 3 years have passed since last update.

renvとBiocMangerで開発者版R環境を整備する

Last updated at Posted at 2019-12-09

R/Bioconductorでパッケージを開発する際には、開発者版のR(R-devel)で動作確認することが推奨されているが(大して守ってないが)、R-develを入れると、これまで使っていたRが使えなくなるため、どのように環境を分けるのかという問題がいつもあった。

以前は、R/Bioconductor開発者のための開発環境の構築のように、R-develが入ったDockerコンテナを作るというやり方を考えたが(実際は大して使ってないが)、ここでは最近renvというパッケージが、バージョン管理に関係しているというのと、BiocManagerがインストールするパッケージのBioCのバージョン管理をしている話しがあったので、これらを組みわせて、BioCのRelease/Devel両方を手元のマシンで同時に扱えるか調べた。

ただし、結論から言うと、うまくいかなかった。

renvはRのプロジェクト毎のバージョン管理をしているだけで、

pyenv local [Pythonのバージョン]

みたいに、R言語のバージョン自体を管理するものではないらしい。

以下、作業した内容。

準備

まず、release/develのディレクトリを用意した。

mkdir release
mkdir devel

次に、remotes, BiocManager, renvをインストールしておいた。

install.packages(c("remotes", "BiocManager"),
    repos="http://cran.r-project.org")
remotes::install_github("rstudio/renv")

releaseディレクトリ内で

まず、release内部でRを起動して、以下を実行した。

renv::init()
renv::snapshot()

パッケージの場所は、以下のようなところにある。

.libPaths()
# [1] "/Users/koki1/Desktop/release/renv/library/R-3.6/x86_64-apple-darwin15.6.0"
# [2] "/private/var/folders/xw/00wshg996txb26ltmrgk8qtr0000gn/T/Rtmp9Hza8c/renv-system-library"

標準パッケージだけが入っている状態らしい。

system(paste0("ls ", .libPaths()[2]))
# KernSmooth    base        cluster     datasets    graphics    methods     nnet        spatial     stats4      tools
# MASS      boot        codetools   foreign     grid        mgcv        parallel    splines     survival    utils
# Matrix        class       compiler    grDevices   lattice     nlme        rpart       stats       tcltk

ここで、Bioc3.10でリリースされたscTGIFパッケージをインストールしてみる。

なお、renvのGitHubにIssueが立っているように、そもそもrenvは以下のようにoptionを設定しないと、BioCパッケージを入れられないらしい。

options(repos = BiocManager::repositories())
BiocManager::install(version="3.10")
BiocManager::valid() 
BiocManager::install("scTGIF")

develディレクトリ内で

途中まではreleaseの時と同様の作業をした。

renv::init()

renv::snapshot()

.libPaths()
# [1] "/Users/koki1/Desktop/devel/renv/library/R-3.6/x86_64-apple-darwin15.6.0"
# [2] "/private/var/folders/xw/00wshg996txb26ltmrgk8qtr0000gn/T/RtmpbXDLVK/renv-system-library"

options(repos = BiocManager::repositories())
BiocManager::install(version="devel")
# エラー: Bioconductor version '3.11' requires R version '4.0'; see
#   https://bioconductor.org/install
options(repos = BiocManager::repositories(version = "devel"))
# エラー: Bioconductor version '3.11' requires R version '4.0'; see
#   https://bioconductor.org/install

ここで、Rの4.0を入れろと怒られて終わった。

どうやら、このやり方で、Devel版のBioCパッケージをインストールできるのは、4月の半ばから10月の半ばだけらしい。

よく知らなかったが、R言語は年に一度のアップデートなのに対して、BioCは半年に一回のアップデートのため、R言語もアップデートする際には、次のRのバージョンで動作確認するために、R-develを入れろということらしい。

なお、pyenv, pipenv, rbenvのように、R自体のバージョンを管理するものとしては、Renv(renvではない)というものが過去にあったらしいが、もう7,8年メンテナンスされていないのと、

.Renv/versions

以下に、特定のバージョンのRのソースを置いて、手作業でコンパイルしておいてくださいという方針がめんどくさいので使ってない。
結局、いいやり方は見つからなかったので、ひたすらR-develだけを使うマシンとかを決めておいて使うぐらいの方が手間がないかも。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3