Description Usage Arguments Details Value See Also Examples
lazydo searches the repo for previous execution of an expression. If a previous execution is found, the result is loaded and returned. Otherwise, the expression is executed and the result stashed.
1 | repo_lazydo(expr, force = F, env = parent.frame())
|
expr |
An object of class expression (the code to run). |
force |
If TRUE, execute expr anyway |
env |
Environment for expr, defaults to parent. |
The expression results are stashed as usual. The name of the resource is obtained by digesting the expression, so it will look like an MD5 string in the repo. Note that the expression, and not its result, will uniquely identify the item in the repo.
The new item is automatically tagged with "stash", "hide" and "lazydo".
Results of the expression (either loaded or computed on the fly).
repo_stash, repo_put
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | rp_path <- file.path(tempdir(), "example_repo")
rp <- repo_open(rp_path, TRUE)
## First run
system.time(rp$lazydo(
{
Sys.sleep(1/10)
x <- 10
}
))
## lazydo is building resource from code.
## Cached item name is: f3c27f11f99dce20919976701d921c62
## user system elapsed
## 0.004 0.000 0.108
## Second run
system.time(rp$lazydo(
{
Sys.sleep(1/10)
x <- 10
}
))
## lazydo found precomputed resource.
## user system elapsed
## 0.001 0.000 0.001
## The item's name in the repo can be obtained as the name of the
## last item added:
l <- length(rp$entries())
resname <- rp$entries()[[l]]$name
cat(rp$entries()[[l]]$description)
## {
## Sys.sleep(1/10)
## x <- 10
## }
rp$rm(resname) ## single cached item cleared
## wiping temporary repo
unlink(rp_path, TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.