Edit
Here is a better example than the one I originally provided. All you need is to wrap your models in a custom function that turns failures into NA
s.
library(drake)
fail_na <- function(code) {
tryCatch(code, error = error_na)
}
error_na <- function(e) {
NA
}
plan <- drake_plan(
failure = fail_na(stop()),
success = fail_na("success")
)
make(plan, keep_going = TRUE)
#> In drake, consider r_make() instead of make(). r_make() runs make() in a fresh R session for enhanced robustness and reproducibility.
#> target success
#> target failure
readd(failure)
#> [1] NA
readd(success)
#> [1] "success"
Created on 2019-11-14 by the reprex package (v0.3.0)
Original answer
It is possible, but it requires some custom code. Below, we need to check that x
is NULL
or missing.
library(drake)
`%||%` <- function(x, y) {
if (is.null(x)) {
y
} else {
x
}
}
na_fallback <- function(x) {
out <- tryCatch(
x %||% NA,
error = function(e) {
NA
}
)
out
}
plan <- drake_plan(
x = stop(),
y = na_fallback(x)
)
make(plan, keep_going = TRUE)
#> In drake, consider r_make() instead of make(). r_make() runs make() in a fresh R session for enhanced robustness and reproducibility.
#> target x
#> fail x
#> target y
readd(y)
#> [1] NA
Created on 2019-11-14 by the reprex package (v0.3.0)