我已经注意到tryCatch无法正确捕获以下错误:它不会显示TRUE,并且不会转到浏览器...
可能是tryCatch函数中的错误吗?
library(formattable)
df1 = structure(list(date = c("2018-12-19", "2018-12-19"),
imo = c(9453391, 9771298),
name = c("SFAKIA WAVE", "MEDI KYOTO"),
speed = c(10.3000001907349, 11.6999998092651),
destination = c("ZA DUR", "ZA RCB"),
subsize = c("Post Panamax", "Post Panamax"),
eta = c("2018-12-27 09:00:00", "2018-12-27 09:00:00"),
ToSAF = c(TRUE, TRUE)),
.Names = c("date", "imo", "name", "speed", "destination", "subsize", "eta", "ToSAF"),
row.names = c(NA, -2L),
class = "data.frame")
tryCatch(expr = {
L = list(formattable::area(row = 3) ~ formattable::formatter('span', style = x ~ formattable::style(display = 'block', 'border-radius' = '4px', 'padding-right' = '4px')))
formattable::formattable(df1, L)
},
error = function(e) {
print(TRUE)
browser()
}
)
评估expression时没有错误formattable::formattable(df1, L)
。您可以通过运行以下命令进行验证:
L <- list(formattable::area(row = 3) ~ formattable::formatter('span', style = x ~ formattable::style(display = 'block', 'border-radius' = '4px', 'padding-right' = '4px')))
test <- try(formattable::formattable(df1, L))
class(test)
[1] "formattable" "data.frame"
如果发生错误,该类应为"try-error"
。当您尝试将print
表达式的输出输出到控制台时,将出现错误。我想你要:
L <- list(formattable::area(row = 3) ~ formattable::formatter('span', style = x ~ formattable::style(display = 'block', 'border-radius' = '4px', 'padding-right' = '4px')))
test <- formattable::formattable(df1, L)
tryCatch(expr = {
print(test)
},
error = function(e) {
print(TRUE)
browser()
}
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句