R supress console output of a system or shell command

二次信任 提交于 2021-02-09 08:16:19

问题


I have this windows-batchfile which I'm calling from R using the shell() command. This batchfile does some calculations and writes them on the disk but also on the screen. I'm interested in the disk-output, only. I cannot change the batchfile.

The batchfile might be something silly like:

@echo off
echo 1 + 2
@echo 1 + 2 > C:\TEMP\batchoutput.txt 
exit

I tried

shell("batchfile.bat", invisible = TRUE)

1 + 2

shell("batchfile.bat", show.output.on.console = FALSE)

Error in system(cmd, intern = intern, wait = wait | intern, show.output.on.console = wait, : formal argument "show.output.on.console" matched by multiple actual arguments

system("batchfile.bat", invisible = T)

1 + 2

system("batchfile.bat", show.output.on.console = F)

Warning message: running command 'C:\TEMP\batchfile.bat' had status 1

Is there a way of supressing the console-output on R?


回答1:


options(warn = -1)
shell("You command")
options(warn = 0)


来源:https://stackoverflow.com/questions/45143689/r-supress-console-output-of-a-system-or-shell-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!