# NOT RUN {
test_with_dir("Quarantine side effects.", {
diagnose() # List all the targets with recorded error logs.
# Define a function doomed to failure.
f <- function(){
stop("unusual error")
}
# Create a workflow plan doomed to failure.
bad_plan <- drake_plan(my_target = f())
# Running the project should generate an error
# when trying to build 'my_target'.
try(make(bad_plan), silent = FALSE)
failed() # List the failed targets from the last make() (my_target).
# List targets that failed at one point or another
# over the course of the project (my_target).
# Drake keeps all the error logs.
diagnose()
# Get the error log, an object of class "error".
error <- diagnose(my_target)$error # See also warnings and messages.
str(error) # See what's inside the error log.
error$calls # View the traceback. (See the traceback() function).
# Use purrr to recover all the warnings.
suppressWarnings(
make(
drake_plan(
x = 1,
y = warning(123),
z = warning(456)
),
verbose = FALSE
)
)
targets <- built(verbose = FALSE)
lapply(targets, diagnose, character_only = TRUE, verbose = FALSE) %>%
setNames(targets) %>%
purrr::map("warnings") %>%
purrr::compact() %>%
unlist
})
# }
Run the code above in your browser using DataLab