Rpy2命令历史

Rpy2 command history

是否可以在Rpy2中获取R单例命令行历史记录?

我试过:

import rpy2.robjects as ro
print(ro.r('history()')

还有:

ro.r('savehistory("hist.Rhistory")')

但我只收到一个 NULL 值或一个空白文件。

函数 history() 显示历史而不是 return 历史(例如,作为字符串向量)。

要捕获该输出,可以编写自定义回调(请参阅 http://rpy2.readthedocs.org/en/version_2.7.x/callbacks.html#write-console ) 或使用 R 的 sink().