0
sink(type='message')
很好,但返回值NULL
对我不利。
然后,我问如何在不使用sink
的情况下将错误记录到文件中?如何在不使用sink()的情况下在R中记录错误?
sink(type='message')
很好,但返回值NULL
对我不利。
然后,我问如何在不使用sink
的情况下将错误记录到文件中?如何在不使用sink()的情况下在R中记录错误?
不知道我是否完全理解你的问题,但如果你想捕捉一个错误,然后控制事件应该发生的错误,你想看看?tryCatch
。这就是说,这里是一个例子,你如何捕捉函数中引发的错误并将其作为字符串返回。
f <- function(...){
tryCatch(is.character(...), error = function(e){
var_e <- capture.output(e, file = "errors", append = TRUE)
readLines("errors") ## just to push the output to our variable at the terminal
})
}
a
> a <- f(noquotes)
> a
[1] "<simpleError in doTryCatch(return(expr), name, parentenv, handler): object 'noquotes' not found>"
> typeof(a)
[1] "character"
这是'sink'的一个很好的选择,但我的脚本将被视为条件对象,我无法获得脚本输出结果。 –
您需要提供更多关于您的意思的信息...例如脚本本身或与其接近的示例以及为什么需要捕获错误 –