【发布时间】:2014-01-01 07:33:41
【问题描述】:
我在 Windows 中使用 system() 从 R 调用名为 molconvert 的命令行程序时遇到一些问题。 molconvert 位于"C:\Program Files\ChemAxon\MarvinBeans\bin"
然后我想调用 system() 或 shell() 来模仿我通过键入
molconvert pdb "C:\molecule conversions\cembrene A.mol"
在命令提示符下并将结果输出收集回 R,如
out=system(...,intern=T)
我似乎在路径中的反斜杠和空格方面遇到了麻烦。 我试过了
dirmolconvert="C:\\Program Files\\ChemAxon\\MarvinBeans\\bin"
shell(shQuote(paste(dirmolconvert,"\\molconvert pdb "C:\\cembrene A.mol",sep="")))
但这给了我“错误:...中的意外符号”并转义“也无济于事。关于我应该如何解决这个问题的任何想法?
或
system(paste(dirmolconvert,"\\molconvert pdb \"C:\\cembrene A.mol\"",sep=""), intern=T)
但这给了我
'C:\Program' not found
有什么想法吗?
编辑: 根据下面的答案,正确的做法显然是
inputdir="C:/Users/Ento/Documents/GCMS/molconvert test"
molconvertdir="C:/Program Files/ChemAxon/MarvinBeans/bin"
molecule="cembrene A.mol"
out=system(paste(shQuote(file.path(molconvertdir, "molconvert.bat")),
"pdb",
shQuote(file.path(inputdir,molecule))),intern=T)
【问题讨论】:
-
如果我使用这种语法:
system('../rgames/test space/norun.bat')我没有错误消息。看看你是否可以对你的路径做同样的事情。
标签: r batch-file system command-prompt