【问题标题】:Reading .RData files into python using rpy2使用 rpy2 将 .RData 文件读入 python
【发布时间】:2015-07-26 02:25:30
【问题描述】:

我正在尝试使用 rpy2 模块将 .RData 文件读入 python。下面是代码

>>> from  rpy2.robjects import r
>>> r.load("path to .rdata file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dell\WinPython-32bit-2.7.6.3\python-2.7.6\lib\site-packages\rpy2\robjects\functions.py", line 170, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "C:\Users\dell\WinPython-32bit-2.7.6.3\python-2.7.6\lib\site-packages\rpy2\robjects\functions.py", line 100, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection

我目前使用的是 Windows 7、64 位机器。请帮忙。

【问题讨论】:

  • 嗨,欢迎来到 SO。你有错误吗?运行代码时发生了什么?
  • @Deepend 是的,错误显示在上面——从第 3 行开始。
  • 无法打开连接...文件路径是否正确? R 在您的 Windows 路径环境变量中吗?这就是我想到的两件事......

标签: python r pandas rpy2 rdata


【解决方案1】:

好的,看来我已经理解这里的问题了。

在指定 .RData 文件的路径时,我使用标准 windows ("\") 目录分隔符指定了路径,而 r.load() (显然)无法识别该路径。但是当我使用“/”目录分隔符时,.rdata 文件加载成功。

【讨论】:

    猜你喜欢
    • 2016-10-30
    • 2015-11-22
    • 1970-01-01
    • 2017-06-16
    • 2013-02-11
    • 2015-09-02
    • 1970-01-01
    • 2015-10-18
    相关资源
    最近更新 更多