问题
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
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 code
print(1:10)
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.
Any help is much appreciated, thanks.
回答1:
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())
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.
回答2:
I found out solution to my own question with the help of @shayaa and @abhiieor.
In case if some one needs to see their output in console they are suppose to use Rscript instead of R CMD BATCH in executable .bat file.
batch code:
"C:\Program Files\R\R-3.2.2\bin\Rscript.exe" Test.R
pause
Test.R code
print("-Hello World!!",stdout())
In above code stdout() will redirect output to console.
来源:https://stackoverflow.com/questions/38549285/r-batch-mode-how-to-see-output-error-of-r-on-console-screen