condaでRの環境構築+jupyter notebookでRを起動
目的
タイトルの通り. devtools周りで途中で躓いたのでメモしておく.
TL;DR
conda create -n r_env r-essentials r-base conda activate r_env conda install r
以下, R.
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'uuid', 'digest'))
conda経由でdevtools
をinstall.
conda install -c conda-forge r-devtools
再びRでIRkernel
をinstall.
devtools::install_github('IRkernel/IRkernel') IRkernel::installspec() # install for the current user IRkernel::installspec(user = FALSE) # install system-wide
これでjupyter notebookからRが使用可能.
0. 環境
OS : macOS High Sierra 10.13.6
conda version : 4.8.3
R version : 3.6.1 (2019-07-05)
1. condaでRの環境を構築
この記事を参考にcondaでRの環境構築をした. しかし, Rをinstall/uninstallを繰り返すと以下のようなエラーが出てきてしまい, 面倒だった. 出てきた際には, 環境丸ごと削除・作成を繰り返した...(疲弊)
dyld: Library not loaded: @rpath/libreadline.6.2.dylib Referenced from: /Users/path/to/envs/r_env/lib/R/lib/libR.dylib Reason: image not found Abort trap: 6
2. R kernelをjupyterに導入
googleで検索するといくつも記事(例えばこの記事)がヒットしたが, devtoolsの導入時にエラーが出てしまい, とても困ってしまった.
checking whether the C compiler works... no configure: error: C compiler cannot create executables ERROR: configuration failed for package ‘git2r’ ERROR: dependencies ‘usethis’, ‘git2r’ are not available for package ‘devtools’
どうやら, conda環境のinstall.packages
経由ではdevtoolsを入れられないらしい....
色々模索したが, なぜCのコンパイラでエラーが出るのか正直よくわからなかった.
解決策と思われるものもいくつか見つけたが, 環境全体が汚れてしまうんじゃないかと心配だったので他の方法を調べた.
そしたら, conda経由でdevtoolsが入れられるようだったのでこちらを採用した.
condaなら環境をよしなにしてくれるだろう......(祈り)
conda install -c conda-forge r-devtools
Rで以下を実行.
devtools::install_github('IRkernel/IRkernel') IRkernel::installspec() # install for the current user IRkernel::installspec(user = FALSE) # install system-wide
これで, jupyter notebookからRが使用できた.