YOwatari's blog

思うままに。

jupyter notebookでRを動かす

iPython notebookが進化して様々な言語を扱えるようになったjupyterが登場しました。
今までpythonのためぐらいにしか使っていませんでしたが、Rを使う機会があったのでjupyterで動かせるようにしてみます。メモです。

下準備

brew install ZMQ

zeromqをインストールしても、libzmq.4.dylibが無いと怒られるので、
とりあえずリンクを作っておきます。もっとまともなやり方はありそうです。

ln -s /usr/local/Cellar/zeromq/4.1.2/lib/libzmq.dylib /usr/local/lib/libzmq.4.dylib

jupyterインストールの準備

github.com

pyenvとvirtualenvが使える前提です。
jupyter notebookをインストールします。

pyenv virtualenv 3.4.3 jupyter
pyenv local jupyter
pip install pycurl
git clone git@github.com:jupyter/notebook.git
cd notebook
pip install -r requirements.txt -e .
pyenv rehash

IRkernelのインストール

github.com

これはRのコンソール上で

install.packages(c('rzmq','repr','IRkernel','IRdisplay'),
                 repos = c('http://irkernel.github.io/', getOption('repos')))
IRkernel::installspec(user=F)

jupyter notebookの起動

jupyter notebook

f:id:wata88:20150703094047p:plain