Reference package in personal library from rpy2

此生再无相见时 提交于 2019-12-12 18:56:31

问题


I have just installed the MSwM package from CRAN into my personal library location via RStudio, and I am trying to call it from Python using rpy2. However, it is giving me this error:

rpy2.rinterface.RRuntimeError: Error in loadNamespace(name) : 
there is no package called 'MSwM'

I have tried referencing the standard package and they have no problems loading. Here is my code in Python:

from rpy2.robjects import r
from rpy2.robjects.packages import importr

base=importr('base')
utils=importr('utils')
markov=importr('MSwM')

So, both base and utils are properly loaded, but markov fails to load. Can anyone shed some light on how I can get packages in personal library location to run in rpy2?(btw my set up is in Windows 7) Just a FYI the current environment set up is like this : R_USER=xxx R_HOME=C:\Program Files\R\R-3.2.2

My personal library is in C:\Users\xxx\Documents\R\win-library\3.2 and I am able to get MSwM loaded and run in RStudio itself.


回答1:


Never mind.I found the answer as importr has the lib_loc parameter to specify the location of the package, so I am doing the following and it is working now:

markov=importr('MSwM',lib_loc = "C:/Users/xxx/Documents/R/win-library/3.2")


来源:https://stackoverflow.com/questions/33309057/reference-package-in-personal-library-from-rpy2

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