This is a set of functions acting as counterparts to the sequential popular apply functions in base R:
btlapply for lapply and btmapply for mapply.
Internally, jobs are created using batchMap on the provided registry.
If no registry is provided, a temporary registry (see argument file.dir of makeRegistry) and batchMap
will be used.
After all jobs are terminated (see waitForJobs), the results are collected and returned as a list.
Note that these functions are only suitable for short and fail-safe operations on batch system. If some jobs fail, you have to retrieve partial results from the registry directory yourself.
Usage
btlapply(
X,
fun,
...,
resources = list(),
n.chunks = NULL,
chunk.size = NULL,
reg = makeRegistry(file.dir = NA)
)
btmapply(
fun,
...,
more.args = list(),
simplify = FALSE,
use.names = TRUE,
resources = list(),
n.chunks = NULL,
chunk.size = NULL,
reg = makeRegistry(file.dir = NA)
)Arguments
- X
[
vector]
Vector to apply over.- fun
[
function]
Function to apply.- ...
[
ANY]
Additional arguments passed tofun(btlapply) or vectors to map over (btmapply).- resources
[
named list]
Computational resources for the jobs to submit. The actual elements of this list (e.g. something like “walltime” or “nodes”) depend on your template file, exceptions are outlined in the section 'Resources'. Default settings for a system can be set in the configuration file by defining the named listdefault.resources. Note that these settings are merged by name, e.g. merginglist(walltime = 300)intolist(walltime = 400, memory = 512)will result inlist(walltime = 300, memory = 512). Same holds for individual job resources passed as additional column ofids(c.f. section 'Resources').- n.chunks
[
integer(1)]
Passed tochunkbeforesubmitJobs.- chunk.size
[
integer(1)]
Passed tochunkbeforesubmitJobs.- reg
[
Registry]
Registry. If not explicitly passed, uses the default registry (seesetDefaultRegistry).- more.args
[
list]
Additional arguments passed tofun.- simplify
[
logical(1)]
Simplify the results usingsimplify2array?- use.names
[
logical(1)]
Use names of the input to name the output?
Examples
btlapply(1:3, function(x) x^2)
#> No readable configuration file found
#> Created registry in '/tmp/batchtools-example/reg' using cluster functions 'Interactive'
#> Adding 3 jobs ...
#> Submitting 3 jobs in 3 chunks using cluster functions 'Interactive' ...
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 4
#>
#> [[3]]
#> [1] 9
#>
btmapply(function(x, y, z) x + y + z, x = 1:3, y = 1:3, more.args = list(z = 1), simplify = TRUE)
#> No readable configuration file found
#> Created registry in '/tmp/RtmpSdeSoD/registry21a26fb61b3d' using cluster functions 'Interactive'
#> Adding 3 jobs ...
#> Submitting 3 jobs in 3 chunks using cluster functions 'Interactive' ...
#> [1] 3 5 7