我正在尝试使用rpy2将R包导入到python3环境中,该方法在过去运行良好。但是,当我使用rpy2中的importr函数导入任何软件包时,rpy2最近一直在引发内部TypeError: 'ExprSexpVector' object is not callable
错误。即使是rpy2文档中最简单的示例代码也无法运行(下面的代码)。
我尝试通过pip将rpy2更新到最新版本。目前适用于Python 3.7.3和rpy2 3.0.5。在具有Mojave 10.14.4和R版本3.6.1的MacOS上运行(重新安装)。
from rpy2.robjects.packages import importr
utils = importr("utils")
第二行代替加载r包,引发以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/packages.py", line 492, in importr
symbol_check_after=symbol_check_after)
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/packages.py", line 204, in __init__
self.__fill_rpy2r__(on_conflict=on_conflict)
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/packages.py", line 330, in __fill_rpy2r__
.__fill_rpy2r__(on_conflict=on_conflict))
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/packages.py", line 264, in __fill_rpy2r__
rpyobj = conversion.rpy2py(riobj)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py", line 827, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/__init__.py", line 207, in _rpy2py_sexpclosure
return SignatureTranslatedFunction(obj)
File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 163, in __init__
formals.names,
File "/usr/local/lib/python3.7/site-packages/rpy2/rinterface_lib/sexp.py", line 180, in names
return embedded.globalenv.find('names')(self)
TypeError: 'ExprSexpVector' object is not callable
运行$ python3 -m rpy2.situation
得到以下结果:
Python version:
3.7.4 (default, Jul 9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)]
Looking for R's HOME:
Environment variable R_HOME: None
Calling `R RHOME`: /Library/Frameworks/R.framework/Resources
InstallPath in the registry: *** Only available on Windows ***
R version:
In the PATH: R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Loading R library from rpy2: OK
Additional directories to load R packages from:
None