运行 R 脚本时创建警告日志文件
Create warning log file when running R script
我想为 R 脚本创建 warning/error 日志。
请看下面的例子:
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) 中:产生了 NaN
但是 1:30 中的循环 i 在 all.rout 文件中只有一行:
有 30 个警告(使用 warnings() 查看它们)
知道如何解决吗?
我根据另一个主题创建了代码:
Output error/warning log (txt file) when running R script under command line
尝试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.
我想为 R 脚本创建 warning/error 日志。
请看下面的例子:
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) 中:产生了 NaN
但是 1:30 中的循环 i 在 all.rout 文件中只有一行:
有 30 个警告(使用 warnings() 查看它们)
知道如何解决吗?
我根据另一个主题创建了代码:
Output error/warning log (txt file) when running R script under command line
尝试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.