Install and use RPy2 (using conda) so that it uses default R installation in /usr/lib/R R

北战南征 提交于 2020-07-20 10:40:08

问题


I want to call functions from my R packages in Python using RPy2. I installed RPy2 using conda and realized it installed a fresh copy of R inside conda... I don't want that. I just want to have and use one R, the default one in /usr/lib/R.

How to do that? How to force conda and Python and RPy2 to use default R installed in /usr/lib/R?


回答1:


Do not use the conda instal to install the rpy2, just use the pip install rpy2. Here are some additional packages you may need to install before the rpy2:

conda install -y PyHamcrest
sudo apt-get install -y libreadline6-dev
pip install rpy2

Some notes:

  1. The which pip should refer to anaconda's path
  2. The environment variable for R (R_HOME and PATH) should be properly set up before you install the rpy2
  3. After the installation, you may encounter an error when calling import rpy2.robjects as robjects:

    RRuntimeWarning: Error: package or namespace load failed for ‘stats’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/usr/local/lib/R/library/stats/libs/stats.so': libRlapack.so: cannot open shared object file: No such file or directory

To solve this, I found a solution in How I solved the error - libRlapack.so: cannot open shared object file: No such file or directory

You need to locate your libRlapack.so file (in my case this file is in /usr/local/lib/R/lib/), or the following command should show the path to this file:

R CMD ldd /usr/local/lib/R/library/stats/libs/stats.so

and then write this path to the /etc/ld.so.conf.d/libR.conf and then run ldconfig:

echo "/usr/local/lib/R/lib/" >> /etc/ld.so.conf.d/libR.conf && ldconfig

That should fix the problem.



来源:https://stackoverflow.com/questions/51486081/install-and-use-rpy2-using-conda-so-that-it-uses-default-r-installation-in-us

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!