这里有一系列令人沮丧的问题。本质上我希望 R 使用命令行参数打开外部程序。我目前正在尝试在 Windows 机器上实现它,理想情况下它可以跨平台工作。
程序(chimera.exe)位于包含空格的目录中:C:\Program Files\Chimera1.15\bin\
命令行选项可以是例如--nogui标志和脚本名称,因此我将从 shell 中编写(除了空间特定之外):
C:\Program Files\Chimera1.15\bin\chimera.exe --nogui scriptfile
如果我进入 windows cmd.exe 到目录本身并只需键入chimera.exe --nogui scriptfile
现在在 R 中:
我一直在使用shell()、shell.exec()和system(),但本质上我失败了,因为空格和/或路径分隔符。
大多数时候,无论出于何种原因,system() 都会打印“127”:
> system("C:/Program Files/Chimera1.15/bin/chimera.exe")
[1] 127`
后/前斜杠使问题进一步复杂化,但无法使其发挥作用:
> system("C:\Program Files\Chimera1.15\bin\chimera.exe")
Error: '\P' is an unrecognized escape in character string starting "C\P"
> system("C:\\Program Files\\Chimera1.15\\bin\\chimera.exe")
[1] 127
> system("C:\\Program\ Files\\Chimera1.15\\bin\\chimera.exe")
[1] 127
> system("C:\\Program\\ Files\\Chimera1.15\\bin\\chimera.exe")
[1] 127
当我将程序安装在没有空格的目录中时,它可以工作。如何转义或传递system()相关命令中的空格,或者如何调用该程序?