在输出文件中捕获Rscript错误 [英] Capturing Rscript errors in an output file

查看:220
本文介绍了在输出文件中捕获Rscript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与类似的命令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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆