我想把一些写东西的表达式直接写入Rscript.exe
的调用( > file
中指定Rscript [options] [-e expression] file [args]
因此没有运行的显式R脚本)。
除了未创建所需文件的事实外,一切似乎都有效。我做错了什么?
# Works:
shell("Rscript -e print(Sys.time())")
# Works:
write(Sys.time(), file='c:/temp/systime.txt')
# No error, but no file created:
shell("Rscript -e write(Sys.time(), file='c:/temp/systime.txt')")
答案 0 :(得分:4)
Rscript使用空格作为分隔符解析其命令行。如果您的R字符串包含嵌入空格,则需要将其包含在引号内以确保它作为完整单元发送到R解析器。
除非您特别需要shell
的功能,否则您也无需使用cmd.exe
。
system("Rscript.exe -e \"write(Sys.time(), file='c:/temp/systime.txt')\"")