【发布时间】:2016-01-20 18:45:52
【问题描述】:
Answer to question about error handling with lapply 在元素失败时总是返回NA 或NULL,即
myfun <- function(s) {
tryCatch(doSomething(s), error = function(e) { return(NULL) }
}
但是,这还不够通用,因为 doSomething(s) 可能会返回 NULL 或 NA 本身。因此,理想情况下,我希望编写myfun,以便在lapply(mylist, myfun) 之后,我可以以某种方式获取失败元素的所有索引。如何做到这一点?
【问题讨论】:
标签: r error-handling lapply