ITの隊長のブログ

ITの隊長のブログです。Rubyを使って仕事しています。最近も色々やっているお(^ω^ = ^ω^)

iPythonからRを実行する

スポンサードリンク

今Jupyterって名前らしい。

iPythonからRが実行できるということを聞いたので、試してみる。

その時のメモ

これはRのコンソールから

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

interface.cpp:22:10: fatal error: 'zmq.h' file not found
#include <zmq.h>
         ^
1 error generated.
make: *** [interface.o] Error 1
ERROR: compilation failed for package ‘rzmq’
* removing ‘/usr/local/lib/R/3.2/site-library/rzmq’

なんか入っていないから実行できないっぽい。

macのコンソールからインストール

$ brew install czmq zmq

またRのコンソールから実行

IRkernel::installspec()
 IRkernel::installspec() でエラー: 
  Jupyter or IPython 3.0 has to be installed but could neither run “jupyter” nor “ipython”, “ipython2” or “ipython3”.
             (Note that “ipython2” is just IPython for Python 2, but still may be IPython 3.0)

うむむ。。。

install.packages('devtools')

...
ERROR: dependency ‘xml2’ is not available for package ‘rversions’
* removing ‘/usr/local/lib/R/3.2/site-library/rversions’
ERROR: dependency ‘rversions’ is not available for package ‘devtools’
* removing ‘/usr/local/lib/R/3.2/site-library/devtools’

macコンソールからから実行

$ brew install xml2

もっかい

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
   共有ライブラリ '/usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so' を読み込めません: 
  dlopen(/usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so, 6): Library not loaded: libxml2.2.dylib
  Referenced from: /usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so
  Reason: image not found 
 エラー:  ロードに失敗しました 
 実行が停止されました 
ERROR: loading failed

(´;ω;`)ブワッ

調べてみる。

stackoverflow.com

あった。

$ pkg-config --libs --cflags  libxml2
Package libxml2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml2' found

なんもない。じゃあインストール。

$ brew install libxml2

はいった!

もっかい

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
   共有ライブラリ '/usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so' を読み込めません: 
  dlopen(/usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so, 6): Library not loaded: libxml2.2.dylib
  Referenced from: /usr/local/lib/R/3.2/site-library/xml2/libs/xml2.so
  Reason: image not found 
 エラー:  ロードに失敗しました 
 実行が停止されました 
ERROR: loading failed

not changed^q^

泣きそうなところを下記サイトに助けられました。

www.perfectlyrandom.org

やったこと

https://cran.r-project.org/web/packages/xml2/index.html

このサイトから、xml2のソースを取得する。

下記リンク(リンク切れになるかもしれませんので、本元から取得ください)

https://cran.r-project.org/src/contrib/xml2_0.1.2.tar.gz

んで、ダウンロードしたtar.gzのファイルを解答して、サイトの「SOLUTION 1」と「SOLUTION 2」を対応する。configureファイルを書き換えて、ビルドする。

んで、圧縮ファイルができるので、それをRコンソールから読み込む。

install.packages("xml2_0.1.2.tar.gz", repos=NULL, type="source")

それで、もっかいdevtoolsを読みだす。

install.packages('devtools')

...

*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (devtools)

やったーヾ(´∀`)ノキャッキャ

> IRkernel::installspec()
 IRkernel::installspec() でエラー: 
  Jupyter or IPython 3.0 has to be installed but could neither run “jupyter” nor “ipython”, “ipython2” or “ipython3”.
             (Note that “ipython2” is just IPython for Python 2, but still may be IPython 3.0)

(・ω・)

(やめようかな。。。)

あきらめようとしていたそのとき。

RをIPython Notebookから使う

この通りにやったらできました。。。なんだったんだろう。。。。