Learn R Programming

drake (version 5.2.1)

diagnose: Get diagnostic metadata on a target.

Description

Diagnostics include errors, warnings, messages, runtimes, and other context/metadata from when a target was built or an import was processed. If your target's last build succeeded, then diagnose(your_target) has the most current information from that build. But if your target failed, then only diagnose(your_target)$error, diagnose(your_target)$warnings, and diagnose(your_target)$messages correspond to the failure, and all the other metadata correspond to the last build that completed without an error.

Usage

diagnose(target = NULL, character_only = FALSE, path = getwd(),
  search = TRUE, cache = drake::get_cache(path = path, search = search,
  verbose = verbose), verbose = drake::default_verbose())

Arguments

target

name of the target of the error to get. Can be a symbol if character_only is FALSE, must be a character if character_only is TRUE.

character_only

logical, whether target should be treated as a character or a symbol. Just like character.only in library().

path

Root directory of the drake project, or if search is TRUE, either the project root or a subdirectory of the project. Ignored if a cache is supplied.

search

logical. If TRUE, search parent directories to find the nearest drake cache. Otherwise, look in the current working directory only. Ignored if a cache is supplied.

cache

drake cache. See new_cache(). If supplied, path and search are ignored.

verbose

logical or numeric, control printing to the console. Use pkgconfig to set the default value of verbose for your R session: for example, pkgconfig::set_config("drake::verbose" = 2).

0 or FALSE:

print nothing.

1 or TRUE:

print only targets to build.

2:

in addition, print checks and cache info.

3:

in addition, print any potentially missing items.

4:

in addition, print imports. Full verbosity.

Value

Either a character vector of target names or an object of class "error".

See Also

failed(), progress(), readd(), drake_plan(), make()

Examples

Run this code
# 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