我想使用运行交互式二进制文件system()
R 内。
通过交互,假设我想从 R 中运行 python 命令行解释器(谁知道为什么,但无论如何......)。
当我从命令行(即 Rterm)运行 R 时,我可以像这样启动 python 解释器:
> system('python.exe')
Python 2.7.2 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # I can now type in python commands and basically use the python
# interpreter until I've had enough.
# Now I'll exit the python interpreter:
>>> exit()
> # Presto, I'm back to the R prompt!
关键是,我可以与 R 中的 python 解释器进行交互,就像我首先从命令行启动解释器一样,并且在完成后可以退出它以返回 R 提示符。
现在,让我们在 R GUI 上尝试同样的操作:
> system('python.exe')
Python 2.7.2 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
> # eh? it exitted?
这只是运行 python.exe (显示欢迎消息),但随后立即退出 - 我无法与 python 解释器交互。
我的问题是——是否有任何方法(在 R GUI 中,即 Windows 中)运行该解释器并以与任何 R 命令行版本相同的方式与其交互?
(仅供参考 - 当我第一次开始学习如何编写 R 包时,作为我的第一个 R 包,我的目标就是能够玩nethack在 R 中工作得很好(我使用 Linux,因此使用命令行 R),除了当我将它带到 Windows RGui 时,它会启动该进程但不能交互,有效地锁定 R,直到我强行结束 NetHack.exe 进程)。