如果我在命令行下运行R脚本(实际上是通过在VBA中调用来运行该脚本),如何将任何错误/警告消息输出到txt文件?
最佳答案
您可以使用sink()
将消息以及警告转移到文件中。诀窍是设置参数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 message sink and close the file connection
sink(type="message")
close(zz)
## Display the log file
readLines("all.Rout")
[1] "Error in log(\"a\") : Non-numeric argument to mathematical function"
关于r - 在命令行下运行R脚本时输出错误/警告日志(txt文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666086/