来自 rpy2 的个人库中的参考包 [英] Reference package in personal library from rpy2
问题描述
我刚刚通过 RStudio 将 CRAN 中的 MSwM 包安装到我的个人库位置,我正在尝试使用 rpy2 从 Python 调用它.但是,它给了我这个错误:
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'
我试过引用标准包,加载没有问题.这是我的 Python 代码:
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')
因此,base 和 utils 都已正确加载,但 Markov 无法加载.谁能解释一下我如何在个人库位置获取包以在 rpy2 中运行?(顺便说一句,我的设置是在 Windows 7 中)仅供参考,当前环境设置如下:R_USER=xxxR_HOME=C:\Program Files\R\R-3.2.2
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
我的个人库位于 C:\Users\xxx\Documents\R\win-library\3.2 中,我能够加载 MSwM 并在 RStudio 中运行.
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.
推荐答案
没关系.我找到了答案,因为 importr 有 lib_loc 参数来指定包的位置,所以我正在执行以下操作并且它现在正在工作:
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")
这篇关于来自 rpy2 的个人库中的参考包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!