gpt4 book ai didi

r - 在命令行下运行R脚本时输出错误/警告日志(txt文件)

转载 作者:行者123 更新时间:2023-12-03 13:40:15 25 4
gpt4 key购买 nike

如果我在命令行下运行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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com