R/100.capture_journals.R
capture_journals.Rd
Evaluate an R expression while collecting journals from completed futures
capture_journals(expr, substitute = TRUE, envir = parent.frame())
The R expression to evaluate
If TRUE, then expr
is substituted, otherwise not.
The environment where expr
should be evaluated
A list of FutureJournal:s.
This function evaluates an R expression and capture the journals signaled by futures as they are completed. A future journal comprise a log of events appearing during the life-span of a future, e.g. the timestamps when the future was created, launched, queried, resolved, and its results are collected.
slow_fcn <- function(x) {
Sys.sleep(x / 10)
sqrt(x)
}
plan(multisession, workers = 2)
js <- capture_journals({
fs <- lapply(3:1, FUN = function(x) future(slow_fcn(x)))
value(fs)
})
## Summarize all journals
js_all <- Reduce(rbind, js)
print(summary(js_all), digits = 2L)
#> Number of futures: 3
#> summary evaluate evaluate_ratio overhead overhead_ratio duration
#> 1 min 0.10 secs 0.28 0.053 secs 0.15 0.37 secs
#> 2 mean 0.21 secs 0.56 0.132 secs 0.35 0.38 secs
#> 3 median 0.23 secs 0.60 0.078 secs 0.21 0.38 secs
#> 4 max 0.30 secs 0.78 0.264 secs 0.68 0.39 secs
#> 5 total 0.64 secs 0.56 0.396 secs 0.35 1.14 secs
#> walltime
#> 1 0.37 secs
#> 2 0.38 secs
#> 3 0.38 secs
#> 4 0.39 secs
#> 5 1.14 secs
## Shut down parallel workers
plan(sequential)