我想为R脚本创建警告/错误日志 请看下面的例子:
setwd(tempdir())
zz <- file("all.Rout", open="wt")
sink(zz, type="message")
for (i in 1:30){
log(i-50)
}
sink(type="message")
close(zz)
我原以为它会招募所有警告:
警告信息:
1:在log(i-50)中:产生NaNs
2:在log(i-50)中:产生NaNs
3:在log(i-50)中:NaNs产生
然而,对于1:30中的循环i,all.rout文件中只有一行:
有30个警告(使用警告()来查看它们)
知道怎么解决吗?
我已根据其他主题创建了代码:
Output error/warning log (txt file) when running R script under command line
答案 0 :(得分:1)
尝试options(warn=1)
来自?options
:
'warn': sets the handling of warning messages. If 'warn' is
negative all warnings are ignored. If 'warn' is zero (the
default) warnings are stored until the top-level function
returns. If 10 or fewer warnings were signalled they will be
printed otherwise a message saying how many were signalled.
An object called 'last.warning' is created and can be printed
through the function 'warnings'. If 'warn' is one, warnings
are printed as they occur. If 'warn' is two or larger all
warnings are turned into errors.