在输出文件中捕获Rscript错误 [英] Capturing Rscript errors in an output file
问题描述
与类似的命令R CMD BATCH
不同,在默认情况下,该命令会生成一个输出文件,该文件包含任何会导致脚本执行停止的错误消息,但我找不到用Rscript
执行此操作的方法.我尝试在Linux Shell中使用管道来实现此目的:
Unlike the similar command R CMD BATCH
which by default produces an output file which contains any error messages which would cause the execution of a script to halt, I have not been able to find a way to do this with Rscript
. I have tried using a pipe in my linux shell to achieve this:
RScript --no-save --no-restore --verbose myRfile.R > outputFile.Rout
,但这只会传递发生错误之前发生的所有输出,因此文件outputFile.R
不包含任何错误信息.有谁知道如何捕获使用RScript
执行R文件并将其保存到文件时发生的任何错误?
but this will only pipe over any output that occurred before an error occurs, so the file outputFile.R
doesn't contain any error information. Does anyone know how to get the capture any errors that occur in executing an R file using RScript
and saving it to a file?
推荐答案
Rscript --no-save --no-restore --verbose myRfile.R > outputFile.Rout 2> errorFile.Rout
将输出和错误放在同一文件中(假设sh/bash)
To put the output and error in the same file (assuming sh/bash)
Rscript --no-save --no-restore --verbose myRfile.R > outputFile.Rout 2>&1
这篇关于在输出文件中捕获Rscript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!