| Action |
Code |
Details |
|
Sequential for-loop
|
foreach(i = 1:4) %do% {
Sys.sleep(1)
}
|
Useful for debugging purposes |
|
Parallel for-each loop
|
foreach(i = 1:4) %dopar% {
Sys.sleep(4)
}
|
|
|
Combine results through concatenation
|
foreach(i=1:4, .combine=c) %dopar% {
1
}
|
|
|
Post-process results
|
foreach(..., .final=as.integer)
|
|
|
Provide initial output object
|
lm0 = lm(y~x, data=dt)
foreach(i = 1:4, .init=lm0) %dopar% {
lm(y~x, data=dt)
}
|
Saves time |
|
Run loop in arbitrary order
|
foreach(..., .inorder=FALSE)
|
More efficient |
|
Load packages needed by the for-loop body
|
foreach(..., .packages=c('data.table'))
|
|
|
Ignore and exclude errors from result
|
foreach(..., .errorhandling='remove')
|
|
|
Expose variable to for-loop body
|
foreach(..., .export=c('var'))
|
|
|
Exclude from export
|
foreach(..., .noexport=c('var'))
|
|
|
Verbose mode
|
foreach(..., .verbose=TRUE)
|
|
| Action |
Code |
Details |
|
Run an expression
|
|
x %<-% { 100 }
y %<-% { 200 }
x + y # blocks until results for x and y are in |
|
Run expression with operator conflict from other package
|
future::`%<-%`(x, { 100 })
|
|
|
Run expression with a label
|
x %<-% { 100 } %label% 'math'
|
|
|
Run expression only once its value is requested
|
x %<-% { 100 } %lazy% TRUE
|
|
|
Run expression with seed
|
RNGkind("L'Ecuyer-CMRG")
x %<-% { rnorm(0, 1) } %seed% {set.seed(1); .Random.seed}
|
|
|
Run expressions and put results in list
|
results = listenv::listenv()
results[1] %<-% 200;
results[2] %<-% 300;
|
|