readd()
returns an object from the cache,
and loadd()
loads one or more objects from the cache
into your environment or session. These objects are usually
targets built by make()
.
readd(target, character_only = FALSE, path = getwd(), search = TRUE,
cache = drake::get_cache(path = path, search = search, verbose =
verbose), namespace = NULL, verbose = drake::default_verbose(),
show_source = FALSE)loadd(..., list = character(0), imported_only = FALSE,
path = getwd(), search = TRUE, cache = drake::get_cache(path =
path, search = search, verbose = verbose), namespace = NULL,
envir = parent.frame(), jobs = 1,
verbose = drake::default_verbose(), deps = FALSE, lazy = "eager",
graph = NULL, replace = TRUE, show_source = FALSE)
If character_only
is TRUE
, then
target
is a character string naming the object to read.
Otherwise, target
is an unquoted symbol with the name of the
object.
logical, whether name
should be treated
as a character or a symbol
(just like character.only
in library()
).
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.
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.
drake cache. See new_cache()
.
If supplied, path
and search
are ignored.
optional character string,
name of the storr
namespace to read from.
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)
.
FALSE
:print nothing.
TRUE
:print only targets to build.
+ checks and cache info.
+ any potentially missing items.
+ imports and writes to the cache.
logical, option to show the command
that produced the target or indicate that the object
was imported (using show_source()
).
targets to load from the cache: as names (symbols),
character strings, or dplyr
-style tidyselect
commands such as starts_with()
.
character vector naming targets to be loaded from the
cache. Similar to the list
argument of remove()
.
logical, whether only imported objects should be loaded.
environment to load objects into. Defaults to the calling environment (current workspace).
number of parallel jobs for loading objects. On
non-Windows systems, the loading process for multiple objects
can be lightly parallelized via parallel::mclapply()
.
just set jobs to be an integer greater than 1. On Windows,
jobs
is automatically demoted to 1.
logical, whether to load any cached
dependencies of the targets
instead of the targets themselves.
This is useful if you know your
target failed and you want to debug the command in an interactive
session with the dependencies in your workspace.
One caveat: to find the dependencies,
loadd()
uses information that was stored
in a drake_config()
list and cached
during the last make()
.
That means you need to have already called make()
if you set deps
to TRUE
.
either a string or a logical. Choices:
"eager"
: no lazy loading. The target is loaded right away
with assign()
.
"promise"
: lazy loading with delayedAssign()
"bind"
: lazy loading with active bindings:
bindr::populate_env()
.
TRUE
: same as "promise"
.
FALSE
: same as "eager"
.
optional igraph object, representation
of the workflow network for getting dependencies
if deps
is TRUE
. If none is supplied,
it will be read from the cache.
logical. If FALSE
,
items already in your environment
will not be replaced.
The cached value of the target
.
NULL
There are two uses for the
loadd()
and readd()
functions:
Exploring the results outside the drake
/make()
pipeline.
When you call make()
to run your project,
drake
puts the targets in a cache, usually a folder called .drake
.
You may want to inspect the targets afterwards, possibly in an
interactive R session. However, the files in the .drake
folder
are organized in a special format created by the
storr package,
which is not exactly human-readable.
To retrieve a target for manual viewing, use readd()
.
To load one or more targets into your session, use loadd()
.
In knitr
/ R Markdown reports.
You can borrow drake
targets in your active code chunks
if you have the right calls to loadd()
and readd()
.
These reports can either run outside the drake
pipeline,
or better yet, as part of the pipeline itself.
If you call knitr_in("your_report.Rmd")
inside a drake_plan()
command, then make()
will scan "your_report.Rmd"
for
calls to loadd()
and readd()
in active code chunks,
and then treat those loaded targets as dependencies.
That way, make()
will automatically (re)run the report if those
dependencies change.
Please do not put calls to loadd()
or readd()
inside
your custom (imported) functions or the commands in your drake_plan()
.
This create confusion inside make()
, which has its own ways of
interacting with the cache.
# NOT RUN {
test_with_dir("Quarantine side effects.", {
load_mtcars_example() # Get the code with drake_example("mtcars").
make(my_plan) # Run the project, build the targets.
readd(reg1) # Return imported object 'reg1' from the cache.
readd(small) # Return targets 'small' from the cache.
readd("large", character_only = TRUE) # Return 'large' from the cache.
# For external files, only the fingerprint/hash is stored.
readd(file_store("report.md"), character_only = TRUE)
})
# }
# NOT RUN {
test_with_dir("Quarantine side effects.", {
load_mtcars_example() # Get the code with drake_example("mtcars").
make(my_plan) # Run the projects, build the targets.
loadd(small) # Load target 'small' into your workspace.
small
# For many targets, you can parallelize loadd()
# using the 'jobs' argument.
loadd(list = c("small", "large"), jobs = 2)
ls()
# How about tidyselect?
loadd(starts_with("summ"))
ls()
# Load the dependencies of the target, coef_regression2_small
loadd(coef_regression2_small, deps = TRUE)
ls()
# Load all the imported objects/functions.
# Note: loadd() excludes foreign imports
# (R objects not originally defined in `envir`
# when `make()` last imported them).
loadd(imported_only = TRUE)
ls()
# Load all the targets listed in the workflow plan
# of the previous `make()`.
# Be sure your computer has enough memory.
loadd()
ls()
# With files, you just get the fingerprint.
loadd(list = file_store("report.md"))
ls() # Should include "\"report.md\"".
get(file_store("report.md"))
})
# }
Run the code above in your browser using DataLab