repo_lazydo: Run expression with cache.

Description Usage Arguments Details Value See Also Examples

View source: R/repo_public.R

Description

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.

Usage

1
repo_lazydo(expr, force = F, env = parent.frame())

Arguments

expr

An object of class expression (the code to run).

force

If TRUE, execute expr anyway

env

Environment for expr, defaults to parent.

Details

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".

Value

Results of the expression (either loaded or computed on the fly).

See Also

repo_stash, repo_put

Examples

 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)

repo documentation built on March 26, 2020, 8:25 p.m.