简体   繁体   English

rpy2 importr 失败并出现错误

[英]rpy2 importr failing with errors

Here is my code and setup;这是我的代码和设置; (Python3) (Python3)

import rpy2

print(rpy2.__version__)

##  The system replies
3.3.3

import rpy2.robjects as ro

print(ro.r("version"))

## The system replies with
...
version.string R version 4.0.2 (2020-06-22)
nickname       Taking Off Again    

from rpy2.robjects.packages import importr

datasets = importr("datasets")

mtcars = datasets('mtcars')['mtcars']

## The error message
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-41-0763eb983987> in <module>
----> 1 mtcars = datasets('mtcars')['mtcars']
      2 
      3 #datasets()

TypeError: 'InstalledSTPackage' object is not callable

I am not sure what's wrong above (in some versions of rpy2 and R, data API is available), I see lots of examples.我不确定上面有什么问题(在某些版本的 rpy2 和 R 中,数据 API 可用),我看到很多例子。 Is there an issue with the 3.3.3 (rpy2) and R (4.0.2)? 3.3.3 (rpy2) 和 R (4.0.2) 有问题吗?

Many Thanks.非常感谢。

Ok, I have found out the answer.好的,我已经找到答案了。

from rpy2.robjects.packages import importr, data ## data is added from rpy2.robjects.packages import importr, data ## data is added

datasets = importr("datasets")数据集 = importr("数据集")

mtcars = data(datasets).fetch('mtcars')['mtcars'] ## changed here mtcars = data(datasets).fetch('mtcars')['mtcars'] ##这里改了

It appears that the API may have changed somewhere. API 似乎在某处发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM