如何识别 Rpy2 R 的所有库

发布于 2024-10-01 15:33:19 字数 491 浏览 10 评论 0原文

如何识别所有库 Rpy2 R.

Rpy2 无法识别库、实用程序和工具。

import rpy2.robjects as robjects

R = robjects.r  

>>> R['library']("utils")

RVector - Python:0x7f65fc85cfc8 / R:0x19bb980

>>> R['library']("tools")

RVector - Python:0x7f65fc85f5a8 / R:0x2419140

(>> from rpy2.robjects.packages import importr 回溯(最近一次调用最后一次): 文件“”,第 1 行,位于 导入错误:没有名为包的模块 )

因为我可以更新 Rpy2 以毫无问题地加载所有库或 R 可以完成的操作。

PS:我在ubuntu上使用R 2.10和python 2.6

How to have recognized all the libraries Rpy2 R.

Rpy2 not recognizing the libraries, utils, and tools.

import rpy2.robjects as robjects

R = robjects.r  

>>> R['library']("utils")

RVector - Python:0x7f65fc85cfc8 / R:0x19bb980

>>> R['library']("tools")

RVector - Python:0x7f65fc85f5a8 / R:0x2419140

(>>> from rpy2.robjects.packages import importr
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named packages
)

as I can update Rpy2 to load all the libraries without problems or R that can be done.

PS: I use R 2.10 and python 2.6 on ubuntu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云悠悠 2024-10-08 15:33:19

为了使 importr 命令正常工作,您可能需要升级 rpy2 的版本 - 尝试检查您的版本:

print rpy2.__version__

我相信您需要 2.1.0 或更高版本。以下内容适用于 2.1.7,但不适用于 2.0.3:

In [1]: import rpy2.robjects as robjects

In [2]: R = robjects.r  

In [3]: from rpy2.robjects.packages import importr

In [4]: importr("utils")
Out[4]: <rpy2.robjects.packages.SignatureTranslatedPackage object at 0x1e96310>

我不确定您要做什么,因为正如 Gavin 提到的那样,这些库应该无需任何额外的导入即可工作。

In order to get the importr command to work, you probably need to upgrade your version of rpy2 -- try checking your version:

print rpy2.__version__

I believe you need version 2.1.0 or greater. The following works for me under 2.1.7 but not on 2.0.3:

In [1]: import rpy2.robjects as robjects

In [2]: R = robjects.r  

In [3]: from rpy2.robjects.packages import importr

In [4]: importr("utils")
Out[4]: <rpy2.robjects.packages.SignatureTranslatedPackage object at 0x1e96310>

I'm not sure what you're trying to do, as those libraries should work without any extra importing, as Gavin has mentioned.

金橙橙 2024-10-08 15:33:19

除非我弄错了——我不使用 Rpy2——这些包(顺便说一下,它们不是库)会在 R 启动时自动加载;您无需执行任何其他操作即可使用它们。这些包中的所有用户可见的函数都在 R 启动期间可用。

另外,您无法更新这些软件包 - 它们是 R。只有当您更新 R 本身时,您才能获得更新。在这一点上,它们与推荐包(如 nlme、mgcv、MASS 等)不同,这些包也在 CRAN 上,并且在 R 版本更新之间更新得更频繁。

Unless I am mistaken - I don't use Rpy2 - these packages (they are not libraries by the way) are loaded automatically when R is started; you do not need to do anything else to make use of them. All the user-visible functions in these packages are made available during R start up.

Also, you can't update these packages - they are R. You only get updates when you update R itself. In this they differ from the Recommended packages (like nlme, mgcv, MASS etc) which are also on CRAN and which are updated more frequently in between R version updates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文