在命令行下运行R脚本时的输出错误/警告日志(txt文件) [英] Output error/warning log (txt file) when running R script under command line

查看:881
本文介绍了在命令行下运行R脚本时的输出错误/警告日志(txt文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在命令行下运行R脚本(实际上是从VBA调用中运行),我如何输出任何错误/警告信息到txt文件?

If I run R script under command line (actually I run that from calling in VBA), how can I output any error/warning messages to a txt file?

推荐答案

您可以使用 sink()将消息和警告转移到文件。诀窍是设置参数 type =message

You can use sink() to divert messages as well as warnings to a file. The trick is to set the argument type="message":

?sink

setwd(tempdir())

## capture messages and errors to a file.
zz <- file("all.Rout", open="wt")
sink(zz, type="message")

try(log("a"))

## reset sink
sink()

## Display the log file

readLines("all.Rout")
[1] "Error in log(\"a\") : Non-numeric argument to mathematical function"

这篇关于在命令行下运行R脚本时的输出错误/警告日志(txt文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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