set {pkgutils} | R Documentation |
A helper function for avoiding long-running computations
if the object to be generated is either already present
or can be read from an Rda
file.
set(name, expr, template = "%s.Rda", env = parent.frame(), inherits = TRUE)
name |
Character scalar indicating the name of an object to be assigned. |
expr |
Expression that will only be evaluated if
|
template |
Character scalar with a template as used
by |
env |
Passed as |
inherits |
Passed as |
If the Rda
file name has no directory component,
it is assumed to be located in the directory given by
getOption("rda_store")
and, if this does not
exist, in the directory given by getwd()
.
An invisible returned integer code indicating what has been done.
The object already existed, nothing was done.
The result of
expr
was assigned to the object, the Rda
file mechanism was not used.
The given
Rda
file was found and its content assigned to the
object.
The given Rda
file was not
found. The result of expr
was assigned to the
object and was also stored in the given Rda
file.
base::assign base::readRDS base::saveRDS
Other coding-functions: L
,
LL
, assert
,
case
, check
, collect
,
contains
, flatten
,
listing
, map_names
,
map_values
, must
,
sql
, unnest
the_answer <- function() {
print("answer requested")
42L
}
set("answer", the_answer(), NULL) # prints 'answer requested'
## [1] "answer requested"
set("answer", the_answer(), NULL) # does not print
answer # 42
## [1] 42