问题描述
以批处理模式运行R代码时,我需要R代码中的消息/错误/日志以显示在控制台屏幕上,而不是.Rout文件中.
While running R code in batch mode i need messages/errors/logs from R code to be shown on console screen instead of .Rout file.
我尝试了所有来自堆栈溢出的帖子(链接复制到下面),并且没有一个显示我想要的输出.
I tried all the posts(links copied below) from stack overflow and none of them are showing me desired output.
- running-r-in-batch-mode-print-to-screen?
- unable-to-run-r-script-through-bat-files-in-windows-server
- r-cmd-batch-output-in-terminal
批处理代码:我也尝试过使用tty0.
batch code: i tried with tty0 as well.
"C:\Program Files\R\R-3.2.2\bin\R.exe" CMD BATCH --slave "Test.R" /dev/tty
Test.R代码
print(1:10)
如果有人可以帮助我显示正确的代码编写方式以在控制台屏幕上显示输出的话,这将非常有帮助.而且我正在Windows环境下工作.
It will be very helpful if some has can help me in showing the correct way of writing the code to show the output in console screen.And i am working on windows environment.
非常感谢您的帮助.
推荐答案
您可以使用stdout
或stderr
重定向要打印的日志.做到这一点的示例方法是:
You can redirect the log that you want to print using stdout
or stderr
. Sample way to do that will be:
write("Hello World!!", stderr())
在这里,我将重定向"Hello World !!".到stderr
.如果在上面的代码片段中使用stdout()
而不是stderr()
,则理想情况下,它应该将日志写入stdout
.但是,尝试写入stdout
时,我遇到了一些问题.
Here I am redirecting "Hello World!!" to stderr
. If you use stdout()
instead of stderr()
in code snippet above then ideally it should write log to stdout
. However I have seen some issues when trying to write into stdout
.
这篇关于R批处理模式:如何在控制台屏幕上查看R的输出/错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!