future_apply() implements base::apply() using future with perfect replication of results, regardless of future backend used. It returns a vector or array or list of values obtained by applying a function to margins of an array or matrix.

future_apply(
  X,
  MARGIN,
  FUN,
  ...,
  simplify = TRUE,
  future.envir = parent.frame(),
  future.stdout = TRUE,
  future.conditions = "condition",
  future.globals = TRUE,
  future.packages = NULL,
  future.lazy = FALSE,
  future.seed = FALSE,
  future.scheduling = 1,
  future.chunk.size = NULL,
  future.label = "future_apply-%d"
)

Arguments

X

an array, including a matrix.

MARGIN

A vector giving the subscripts which the function will be applied over. For example, for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. Where X has named dimnames, it can be a character vector selecting dimension names.

FUN

A function taking at least one argument.

simplify

a logical indicating whether results should be simplified if possible.

future.envir

An environment passed as argument envir to future::future() as-is.

future.stdout

If TRUE (default), then the standard output of the underlying futures is captured, and re-outputted as soon as possible. If FALSE, any output is silenced (by sinking it to the null device as it is outputted). If NA (not recommended), output is not intercepted.

future.conditions

A character string of conditions classes to be captured and relayed. The default is the same as the condition argument of future::Future(). To not intercept conditions, use conditions = character(0L). Errors are always relayed.

future.globals

A logical, a character vector, or a named list for controlling how globals are handled. For details, see below section.

future.packages

(optional) a character vector specifying packages to be attached in the R environment evaluating the future.

future.lazy

Specifies whether the futures should be resolved lazily or eagerly (default).

future.seed

A logical or an integer (of length one or seven), or a list of length(X) with pre-generated random seeds. For details, see below section.

future.scheduling

Average number of futures ("chunks") per worker. If 0.0, then a single future is used to process all elements of X. If 1.0 or TRUE, then one future per worker is used. If 2.0, then each worker will process two futures (if there are enough elements in X). If Inf or FALSE, then one future per element of X is used. Only used if future.chunk.size is NULL.

future.chunk.size

The average number of elements per future ("chunk"). If Inf, then all elements are processed in a single future. If NULL, then argument future.scheduling is used.

future.label

If a character string, then each future is assigned a label sprintf(future.label, chunk_idx). If TRUE, then the same as future.label = "future_lapply-%d". If FALSE, no labels are assigned.

...

(optional) Additional arguments passed to FUN(), except future.* arguments, which are passed on to future_lapply() used internally.

Value

Returns a vector or array or list of values obtained by applying a function to margins of an array or matrix. See base::apply() for details.

Author

The implementations of future_apply() is adopted from the source code of the corresponding base R function, which is licensed under GPL (>= 2) with 'The R Core Team' as the copyright holder.

Examples

## --------------------------------------------------------- ## apply() ## --------------------------------------------------------- X <- matrix(c(1:4, 1, 6:8), nrow = 2L) Y0 <- apply(X, MARGIN = 1L, FUN = table) Y1 <- future_apply(X, MARGIN = 1L, FUN = table)
#> [13:58:13.200] getGlobalsAndPackagesXApply() ...
#> [13:58:13.200] - future.globals: TRUE
#> [13:58:13.249] - globals found/used: [n=1] ‘FUN’
#> [13:58:13.249] - needed namespaces: [n=0]
#> [13:58:13.249] Finding globals ... DONE
#> [13:58:13.250] - use_args: TRUE
#> [13:58:13.250] - Getting '...' globals ...
#> [13:58:13.251] - '...' content: [n=0]
#> [13:58:13.251] List of 1 #> [13:58:13.251] $ ...: list() #> [13:58:13.251] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.251] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.251] - attr(*, "where")=List of 1 #> [13:58:13.251] ..$ ...:<environment: 0x5572e925ad18> #> [13:58:13.251] - attr(*, "resolved")= logi TRUE #> [13:58:13.251] - attr(*, "total_size")= num NA
#> [13:58:13.257] - Getting '...' globals ... DONE
#> [13:58:13.257] Globals to be used in all futures (chunks): [n=2] ‘...future.FUN’, ‘...’
#> [13:58:13.257] List of 2 #> [13:58:13.257] $ ...future.FUN:function (..., exclude = if (useNA == "no") c(NA, NaN), useNA = c("no", #> [13:58:13.257] "ifany", "always"), dnn = list.names(...), deparse.level = 1) #> [13:58:13.257] $ ... : list() #> [13:58:13.257] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.257] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.257] - attr(*, "where")=List of 2 #> [13:58:13.257] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:13.257] ..$ ... :<environment: 0x5572e925ad18> #> [13:58:13.257] - attr(*, "resolved")= logi FALSE #> [13:58:13.257] - attr(*, "total_size")= num 336976
#> [13:58:13.261] Packages to be attached in all futures: [n=0]
#> [13:58:13.261] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:13.261] future_lapply() ...
#> [13:58:13.293] Number of chunks: 1
#> [13:58:13.293] getGlobalsAndPackagesXApply() ...
#> [13:58:13.293] - future.globals: <name-value list> with names ‘list()’
#> [13:58:13.294] - use_args: TRUE
#> [13:58:13.294] Globals to be used in all futures (chunks): [n=2] ‘...’, ‘...future.FUN’
#> [13:58:13.294] List of 2 #> [13:58:13.294] $ ... : list() #> [13:58:13.294] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.294] $ ...future.FUN:function (..., exclude = if (useNA == "no") c(NA, NaN), useNA = c("no", #> [13:58:13.294] "ifany", "always"), dnn = list.names(...), deparse.level = 1) #> [13:58:13.294] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.294] - attr(*, "where")=List of 2 #> [13:58:13.294] ..$ ... :<environment: 0x5572e925ad18> #> [13:58:13.294] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:13.294] - attr(*, "resolved")= logi FALSE #> [13:58:13.294] - attr(*, "total_size")= num NA
#> [13:58:13.297] Packages to be attached in all futures: [n=0]
#> [13:58:13.297] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:13.297] Number of futures (= number of chunks): 1
#> [13:58:13.297] Launching 1 futures (chunks) ...
#> [13:58:13.297] Chunk #1 of 1 ...
#> [13:58:13.298] - Adjusted option 'future.globals.maxSize': Inf -> 2 * Inf = Inf (bytes)
#> [13:58:13.298] - seeds: <none>
#> [13:58:13.331] Created future:
#> [13:58:13.331] SequentialFuture: #> [13:58:13.331] Label: ‘future_apply-1’ #> [13:58:13.331] Expression: #> [13:58:13.331] { #> [13:58:13.331] do.call(function(...) { #> [13:58:13.331] ...future.globals.maxSize.org <- getOption("future.globals.maxSize") #> [13:58:13.331] if (!identical(...future.globals.maxSize.org, ...future.globals.maxSize)) { #> [13:58:13.331] oopts <- options(future.globals.maxSize = ...future.globals.maxSize) #> [13:58:13.331] on.exit(options(oopts), add = TRUE) #> [13:58:13.331] } #> [13:58:13.331] { #> [13:58:13.331] lapply(seq_along(...future.elements_ii), FUN = function(jj) { #> [13:58:13.331] ...future.X_jj <- ...future.elements_ii[[jj]] #> [13:58:13.331] ...future.FUN(...future.X_jj, ...) #> [13:58:13.331] }) #> [13:58:13.331] } #> [13:58:13.331] }, args = future.call.arguments) #> [13:58:13.331] } #> [13:58:13.331] Lazy evaluation: FALSE #> [13:58:13.331] Asynchronous evaluation: FALSE #> [13:58:13.331] Local evaluation: TRUE #> [13:58:13.331] Environment: 0x5572e9181490 #> [13:58:13.331] Capture standard output: TRUE #> [13:58:13.331] Capture condition classes: ‘condition’ (excluding ‘nothing’) #> [13:58:13.331] Globals: 5 objects totaling 329.29 KiB (DotDotDotList ‘future.call.arguments’ of 0 bytes, function ‘...future.FUN’ of 329.08 KiB, list ‘...future.elements_ii’ of 160 bytes, NULL ‘...future.seeds_ii’ of 0 bytes, numeric ‘...future.globals.maxSize’ of 56 bytes) #> [13:58:13.331] Packages: <none> #> [13:58:13.331] L'Ecuyer-CMRG RNG seed: <none> (seed = FALSE) #> [13:58:13.331] Resolved: TRUE #> [13:58:13.331] Value: 2.21 KiB of class ‘list’ #> [13:58:13.331] Early signaling: FALSE #> [13:58:13.331] Owner process: 9d04a638-80d7-2cb1-c9c4-7dbd6de2ef73 #> [13:58:13.331] Class: ‘SequentialFuture’, ‘UniprocessFuture’, ‘Future’, ‘environment’
#> [13:58:13.333] Chunk #1 of 1 ... DONE
#> [13:58:13.333] Launching 1 futures (chunks) ... DONE
#> [13:58:13.333] Resolving 1 futures (chunks) ...
#> [13:58:13.334] - Number of value chunks collected: 1
#> [13:58:13.335] Resolving 1 futures (chunks) ... DONE
#> [13:58:13.335] Reducing values from 1 chunks ...
#> [13:58:13.335] - Number of values collected after concatenation: 2
#> [13:58:13.335] - Number of values expected: 2
#> [13:58:13.335] Reducing values from 1 chunks ... DONE
#> [13:58:13.335] future_lapply() ... DONE
print(Y1)
#> [[1]] #> ...future.X_jj #> 1 3 7 #> 2 1 1 #> #> [[2]] #> ...future.X_jj #> 2 4 6 8 #> 1 1 1 1 #>
stopifnot(all.equal(Y1, Y0, check.attributes = FALSE)) ## FIXME Y0 <- apply(X, MARGIN = 1L, FUN = stats::quantile) Y1 <- future_apply(X, MARGIN = 1L, FUN = stats::quantile)
#> [13:58:13.340] getGlobalsAndPackagesXApply() ...
#> [13:58:13.340] - future.globals: TRUE
#> [13:58:13.342] - globals found/used: [n=1] ‘FUN’
#> [13:58:13.342] - needed namespaces: [n=1] ‘stats’
#> [13:58:13.342] Finding globals ... DONE
#> [13:58:13.343] - use_args: TRUE
#> [13:58:13.343] - Getting '...' globals ...
#> [13:58:13.343] - '...' content: [n=0]
#> [13:58:13.343] List of 1 #> [13:58:13.343] $ ...: list() #> [13:58:13.343] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.343] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.343] - attr(*, "where")=List of 1 #> [13:58:13.343] ..$ ...:<environment: 0x5572e91155e8> #> [13:58:13.343] - attr(*, "resolved")= logi TRUE #> [13:58:13.343] - attr(*, "total_size")= num NA
#> [13:58:13.346] - Getting '...' globals ... DONE
#> [13:58:13.346] Globals to be used in all futures (chunks): [n=2] ‘...future.FUN’, ‘...’
#> [13:58:13.346] List of 2 #> [13:58:13.346] $ ...future.FUN:function (x, ...) #> [13:58:13.346] $ ... : list() #> [13:58:13.346] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.346] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.346] - attr(*, "where")=List of 2 #> [13:58:13.346] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:13.346] ..$ ... :<environment: 0x5572e91155e8> #> [13:58:13.346] - attr(*, "resolved")= logi FALSE #> [13:58:13.346] - attr(*, "total_size")= num 1248
#> [13:58:13.349] Packages to be attached in all futures: [n=1] ‘stats’
#> [13:58:13.349] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:13.350] future_lapply() ...
#> [13:58:13.350] Number of chunks: 1
#> [13:58:13.351] getGlobalsAndPackagesXApply() ...
#> [13:58:13.351] - future.globals: <name-value list> with names ‘list()’
#> [13:58:13.351] - use_args: TRUE
#> [13:58:13.351] Globals to be used in all futures (chunks): [n=2] ‘...’, ‘...future.FUN’
#> [13:58:13.351] List of 2 #> [13:58:13.351] $ ... : list() #> [13:58:13.351] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:13.351] $ ...future.FUN:function (x, ...) #> [13:58:13.351] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:13.351] - attr(*, "where")=List of 2 #> [13:58:13.351] ..$ ... :<environment: 0x5572e91155e8> #> [13:58:13.351] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:13.351] - attr(*, "resolved")= logi FALSE #> [13:58:13.351] - attr(*, "total_size")= num NA
#> [13:58:13.356] Packages to be attached in all futures: [n=1] ‘stats’
#> [13:58:13.356] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:13.356] Number of futures (= number of chunks): 1
#> [13:58:13.356] Launching 1 futures (chunks) ...
#> [13:58:13.357] Chunk #1 of 1 ...
#> [13:58:13.357] - Adjusted option 'future.globals.maxSize': Inf -> 2 * Inf = Inf (bytes)
#> [13:58:13.357] - seeds: <none>
#> [13:58:13.362] Created future:
#> [13:58:13.362] SequentialFuture: #> [13:58:13.362] Label: ‘future_apply-1’ #> [13:58:13.362] Expression: #> [13:58:13.362] { #> [13:58:13.362] do.call(function(...) { #> [13:58:13.362] ...future.globals.maxSize.org <- getOption("future.globals.maxSize") #> [13:58:13.362] if (!identical(...future.globals.maxSize.org, ...future.globals.maxSize)) { #> [13:58:13.362] oopts <- options(future.globals.maxSize = ...future.globals.maxSize) #> [13:58:13.362] on.exit(options(oopts), add = TRUE) #> [13:58:13.362] } #> [13:58:13.362] { #> [13:58:13.362] lapply(seq_along(...future.elements_ii), FUN = function(jj) { #> [13:58:13.362] ...future.X_jj <- ...future.elements_ii[[jj]] #> [13:58:13.362] ...future.FUN(...future.X_jj, ...) #> [13:58:13.362] }) #> [13:58:13.362] } #> [13:58:13.362] }, args = future.call.arguments) #> [13:58:13.362] } #> [13:58:13.362] Lazy evaluation: FALSE #> [13:58:13.362] Asynchronous evaluation: FALSE #> [13:58:13.362] Local evaluation: TRUE #> [13:58:13.362] Environment: 0x5572e9181490 #> [13:58:13.362] Capture standard output: TRUE #> [13:58:13.362] Capture condition classes: ‘condition’ (excluding ‘nothing’) #> [13:58:13.362] Globals: 5 objects totaling 1.43 KiB (DotDotDotList ‘future.call.arguments’ of 0 bytes, function ‘...future.FUN’ of 1.22 KiB, list ‘...future.elements_ii’ of 160 bytes, NULL ‘...future.seeds_ii’ of 0 bytes, numeric ‘...future.globals.maxSize’ of 56 bytes) #> [13:58:13.362] Packages: 1 packages (‘stats’) #> [13:58:13.362] L'Ecuyer-CMRG RNG seed: <none> (seed = FALSE) #> [13:58:13.362] Resolved: TRUE #> [13:58:13.362] Value: 1.14 KiB of class ‘list’ #> [13:58:13.362] Early signaling: FALSE #> [13:58:13.362] Owner process: 9d04a638-80d7-2cb1-c9c4-7dbd6de2ef73 #> [13:58:13.362] Class: ‘SequentialFuture’, ‘UniprocessFuture’, ‘Future’, ‘environment’
#> [13:58:13.364] Chunk #1 of 1 ... DONE
#> [13:58:13.364] Launching 1 futures (chunks) ... DONE
#> [13:58:13.364] Resolving 1 futures (chunks) ...
#> [13:58:13.365] - Number of value chunks collected: 1
#> [13:58:13.365] Resolving 1 futures (chunks) ... DONE
#> [13:58:13.365] Reducing values from 1 chunks ...
#> [13:58:13.365] - Number of values collected after concatenation: 2
#> [13:58:13.365] - Number of values expected: 2
#> [13:58:13.365] Reducing values from 1 chunks ... DONE
#> [13:58:13.366] future_lapply() ... DONE
print(Y1)
#> [,1] [,2] #> 0% 1 2.0 #> 25% 1 3.5 #> 50% 2 5.0 #> 75% 4 6.5 #> 100% 7 8.0
stopifnot(all.equal(Y1, Y0)) ## --------------------------------------------------------- ## Parallel Random Number Generation ## --------------------------------------------------------- # \donttest{ ## Regardless of the future plan, the number of workers, and ## where they are, the random numbers produced are identical X <- matrix(c(1:4, 1, 6:8), nrow = 2L) plan(multisession) Y1 <- future_apply(X, MARGIN = 1L, FUN = sample, future.seed = 0xBEEF)
#> [13:58:14.402] getGlobalsAndPackagesXApply() ...
#> [13:58:14.403] - future.globals: TRUE
#> [13:58:14.408] - globals found/used: [n=1] ‘FUN’
#> [13:58:14.408] - needed namespaces: [n=0]
#> [13:58:14.408] Finding globals ... DONE
#> [13:58:14.408] - use_args: TRUE
#> [13:58:14.409] - Getting '...' globals ...
#> [13:58:14.409] - '...' content: [n=0]
#> [13:58:14.409] List of 1 #> [13:58:14.409] $ ...: list() #> [13:58:14.409] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.409] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.409] - attr(*, "where")=List of 1 #> [13:58:14.409] ..$ ...:<environment: 0x5572e9fa2cb8> #> [13:58:14.409] - attr(*, "resolved")= logi TRUE #> [13:58:14.409] - attr(*, "total_size")= num NA
#> [13:58:14.413] - Getting '...' globals ... DONE
#> [13:58:14.413] Globals to be used in all futures (chunks): [n=2] ‘...future.FUN’, ‘...’
#> [13:58:14.413] List of 2 #> [13:58:14.413] $ ...future.FUN:function (x, size, replace = FALSE, prob = NULL) #> [13:58:14.413] $ ... : list() #> [13:58:14.413] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.413] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.413] - attr(*, "where")=List of 2 #> [13:58:14.413] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:14.413] ..$ ... :<environment: 0x5572e9fa2cb8> #> [13:58:14.413] - attr(*, "resolved")= logi FALSE #> [13:58:14.413] - attr(*, "total_size")= num 36296
#> [13:58:14.417] Packages to be attached in all futures: [n=0]
#> [13:58:14.417] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:14.424] future_lapply() ...
#> [13:58:14.427] Generating random seeds ...
#> [13:58:14.428] Generating random seed streams for 2 elements ...
#> [13:58:14.428] Generating random seed streams for 2 elements ... DONE
#> [13:58:14.429] Generating random seeds ... DONE
#> [13:58:14.436] Number of chunks: 2
#> [13:58:14.436] getGlobalsAndPackagesXApply() ...
#> [13:58:14.437] - future.globals: <name-value list> with names ‘list()’
#> [13:58:14.437] - use_args: TRUE
#> [13:58:14.437] Globals to be used in all futures (chunks): [n=2] ‘...’, ‘...future.FUN’
#> [13:58:14.437] List of 2 #> [13:58:14.437] $ ... : list() #> [13:58:14.437] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.437] $ ...future.FUN:function (x, size, replace = FALSE, prob = NULL) #> [13:58:14.437] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.437] - attr(*, "where")=List of 2 #> [13:58:14.437] ..$ ... :<environment: 0x5572e9fa2cb8> #> [13:58:14.437] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:14.437] - attr(*, "resolved")= logi FALSE #> [13:58:14.437] - attr(*, "total_size")= num NA
#> [13:58:14.441] Packages to be attached in all futures: [n=0]
#> [13:58:14.442] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:14.442] Number of futures (= number of chunks): 2
#> [13:58:14.442] Launching 2 futures (chunks) ...
#> [13:58:14.442] Chunk #1 of 2 ...
#> [13:58:14.442] - seeds: [1] <seeds>
#> [13:58:14.500] Created future:
#> [13:58:14.501] MultisessionFuture: #> [13:58:14.501] Label: ‘future_apply-1’ #> [13:58:14.501] Expression: #> [13:58:14.501] { #> [13:58:14.501] do.call(function(...) { #> [13:58:14.501] ...future.globals.maxSize.org <- getOption("future.globals.maxSize") #> [13:58:14.501] if (!identical(...future.globals.maxSize.org, ...future.globals.maxSize)) { #> [13:58:14.501] oopts <- options(future.globals.maxSize = ...future.globals.maxSize) #> [13:58:14.501] on.exit(options(oopts), add = TRUE) #> [13:58:14.501] } #> [13:58:14.501] { #> [13:58:14.501] lapply(seq_along(...future.elements_ii), FUN = function(jj) { #> [13:58:14.501] ...future.X_jj <- ...future.elements_ii[[jj]] #> [13:58:14.501] assign(".Random.seed", ...future.seeds_ii[[jj]], #> [13:58:14.501] envir = globalenv(), inherits = FALSE) #> [13:58:14.501] ...future.FUN(...future.X_jj, ...) #> [13:58:14.501] }) #> [13:58:14.501] } #> [13:58:14.501] }, args = future.call.arguments) #> [13:58:14.501] } #> [13:58:14.501] Lazy evaluation: FALSE #> [13:58:14.501] Asynchronous evaluation: TRUE #> [13:58:14.501] Local evaluation: TRUE #> [13:58:14.501] Environment: 0x5572e9181490 #> [13:58:14.501] Capture standard output: TRUE #> [13:58:14.501] Capture condition classes: ‘condition’ (excluding ‘nothing’) #> [13:58:14.501] Globals: 5 objects totaling 35.60 KiB (DotDotDotList ‘future.call.arguments’ of 0 bytes, function ‘...future.FUN’ of 35.45 KiB, list ‘...future.elements_ii’ of 80 bytes, list ‘...future.seeds_ii’ of 80 bytes, NULL ‘...future.globals.maxSize’ of 0 bytes) #> [13:58:14.501] Packages: <none> #> [13:58:14.501] L'Ecuyer-CMRG RNG seed: <none> (seed = NULL) #> [13:58:14.501] Resolved: FALSE #> [13:58:14.501] Value: <not collected> #> [13:58:14.501] Conditions captured: <none> #> [13:58:14.501] Early signaling: FALSE #> [13:58:14.501] Owner process: 9d04a638-80d7-2cb1-c9c4-7dbd6de2ef73 #> [13:58:14.501] Class: ‘MultisessionFuture’, ‘ClusterFuture’, ‘MultiprocessFuture’, ‘Future’, ‘environment’
#> [13:58:14.519] Chunk #1 of 2 ... DONE
#> [13:58:14.520] Chunk #2 of 2 ...
#> [13:58:14.520] - seeds: [1] <seeds>
#> [13:58:14.627] Created future:
#> [13:58:14.627] MultisessionFuture: #> [13:58:14.627] Label: ‘future_apply-2’ #> [13:58:14.627] Expression: #> [13:58:14.627] { #> [13:58:14.627] do.call(function(...) { #> [13:58:14.627] ...future.globals.maxSize.org <- getOption("future.globals.maxSize") #> [13:58:14.627] if (!identical(...future.globals.maxSize.org, ...future.globals.maxSize)) { #> [13:58:14.627] oopts <- options(future.globals.maxSize = ...future.globals.maxSize) #> [13:58:14.627] on.exit(options(oopts), add = TRUE) #> [13:58:14.627] } #> [13:58:14.627] { #> [13:58:14.627] lapply(seq_along(...future.elements_ii), FUN = function(jj) { #> [13:58:14.627] ...future.X_jj <- ...future.elements_ii[[jj]] #> [13:58:14.627] assign(".Random.seed", ...future.seeds_ii[[jj]], #> [13:58:14.627] envir = globalenv(), inherits = FALSE) #> [13:58:14.627] ...future.FUN(...future.X_jj, ...) #> [13:58:14.627] }) #> [13:58:14.627] } #> [13:58:14.627] }, args = future.call.arguments) #> [13:58:14.627] } #> [13:58:14.627] Lazy evaluation: FALSE #> [13:58:14.627] Asynchronous evaluation: TRUE #> [13:58:14.627] Local evaluation: TRUE #> [13:58:14.627] Environment: 0x5572e9181490 #> [13:58:14.627] Capture standard output: TRUE #> [13:58:14.627] Capture condition classes: ‘condition’ (excluding ‘nothing’) #> [13:58:14.627] Globals: 5 objects totaling 35.60 KiB (DotDotDotList ‘future.call.arguments’ of 0 bytes, function ‘...future.FUN’ of 35.45 KiB, list ‘...future.elements_ii’ of 80 bytes, list ‘...future.seeds_ii’ of 80 bytes, NULL ‘...future.globals.maxSize’ of 0 bytes) #> [13:58:14.627] Packages: <none> #> [13:58:14.627] L'Ecuyer-CMRG RNG seed: <none> (seed = NULL) #> [13:58:14.627] Resolved: FALSE #> [13:58:14.627] Value: <not collected> #> [13:58:14.627] Conditions captured: <none> #> [13:58:14.627] Early signaling: FALSE #> [13:58:14.627] Owner process: 9d04a638-80d7-2cb1-c9c4-7dbd6de2ef73 #> [13:58:14.627] Class: ‘MultisessionFuture’, ‘ClusterFuture’, ‘MultiprocessFuture’, ‘Future’, ‘environment’
#> [13:58:14.641] Chunk #2 of 2 ... DONE
#> [13:58:14.641] Launching 2 futures (chunks) ... DONE
#> [13:58:14.641] Resolving 2 futures (chunks) ...
#> [13:58:14.756] - Number of value chunks collected: 2
#> [13:58:14.756] Resolving 2 futures (chunks) ... DONE
#> [13:58:14.756] Reducing values from 2 chunks ...
#> [13:58:14.756] - Number of values collected after concatenation: 2
#> [13:58:14.757] - Number of values expected: 2
#> [13:58:14.757] Reducing values from 2 chunks ... DONE
#> [13:58:14.757] future_lapply() ... DONE
print(Y1)
#> [,1] [,2] #> [1,] 7 6 #> [2,] 1 8 #> [3,] 3 4 #> [4,] 1 2
plan(sequential) Y2 <- future_apply(X, MARGIN = 1L, FUN = sample, future.seed = 0xBEEF)
#> [13:58:14.784] getGlobalsAndPackagesXApply() ...
#> [13:58:14.789] - future.globals: TRUE
#> [13:58:14.794] - globals found/used: [n=1] ‘FUN’
#> [13:58:14.794] - needed namespaces: [n=0]
#> [13:58:14.794] Finding globals ... DONE
#> [13:58:14.795] - use_args: TRUE
#> [13:58:14.795] - Getting '...' globals ...
#> [13:58:14.795] - '...' content: [n=0]
#> [13:58:14.795] List of 1 #> [13:58:14.795] $ ...: list() #> [13:58:14.795] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.795] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.795] - attr(*, "where")=List of 1 #> [13:58:14.795] ..$ ...:<environment: 0x5572e734aab8> #> [13:58:14.795] - attr(*, "resolved")= logi TRUE #> [13:58:14.795] - attr(*, "total_size")= num NA
#> [13:58:14.799] - Getting '...' globals ... DONE
#> [13:58:14.799] Globals to be used in all futures (chunks): [n=2] ‘...future.FUN’, ‘...’
#> [13:58:14.799] List of 2 #> [13:58:14.799] $ ...future.FUN:function (x, size, replace = FALSE, prob = NULL) #> [13:58:14.799] $ ... : list() #> [13:58:14.799] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.799] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.799] - attr(*, "where")=List of 2 #> [13:58:14.799] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:14.799] ..$ ... :<environment: 0x5572e734aab8> #> [13:58:14.799] - attr(*, "resolved")= logi FALSE #> [13:58:14.799] - attr(*, "total_size")= num 36296
#> [13:58:14.803] Packages to be attached in all futures: [n=0]
#> [13:58:14.803] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:14.803] future_lapply() ...
#> [13:58:14.806] Generating random seeds ...
#> [13:58:14.806] Generating random seed streams for 2 elements ...
#> [13:58:14.806] Generating random seed streams for 2 elements ... DONE
#> [13:58:14.806] Generating random seeds ... DONE
#> [13:58:14.806] Number of chunks: 1
#> [13:58:14.807] getGlobalsAndPackagesXApply() ...
#> [13:58:14.807] - future.globals: <name-value list> with names ‘list()’
#> [13:58:14.807] - use_args: TRUE
#> [13:58:14.807] Globals to be used in all futures (chunks): [n=2] ‘...’, ‘...future.FUN’
#> [13:58:14.807] List of 2 #> [13:58:14.807] $ ... : list() #> [13:58:14.807] ..- attr(*, "class")= chr [1:2] "DotDotDotList" "list" #> [13:58:14.807] $ ...future.FUN:function (x, size, replace = FALSE, prob = NULL) #> [13:58:14.807] - attr(*, "class")= chr [1:3] "FutureGlobals" "Globals" "list" #> [13:58:14.807] - attr(*, "where")=List of 2 #> [13:58:14.807] ..$ ... :<environment: 0x5572e734aab8> #> [13:58:14.807] ..$ ...future.FUN:<environment: R_EmptyEnv> #> [13:58:14.807] - attr(*, "resolved")= logi FALSE #> [13:58:14.807] - attr(*, "total_size")= num NA
#> [13:58:14.811] Packages to be attached in all futures: [n=0]
#> [13:58:14.811] getGlobalsAndPackagesXApply() ... DONE
#> [13:58:14.811] Number of futures (= number of chunks): 1
#> [13:58:14.811] Launching 1 futures (chunks) ...
#> [13:58:14.811] Chunk #1 of 1 ...
#> [13:58:14.811] - Adjusted option 'future.globals.maxSize': Inf -> 2 * Inf = Inf (bytes)
#> [13:58:14.812] - seeds: [2] <seeds>
#> [13:58:14.814] Created future:
#> [13:58:14.814] SequentialFuture: #> [13:58:14.814] Label: ‘future_apply-1’ #> [13:58:14.814] Expression: #> [13:58:14.814] { #> [13:58:14.814] do.call(function(...) { #> [13:58:14.814] ...future.globals.maxSize.org <- getOption("future.globals.maxSize") #> [13:58:14.814] if (!identical(...future.globals.maxSize.org, ...future.globals.maxSize)) { #> [13:58:14.814] oopts <- options(future.globals.maxSize = ...future.globals.maxSize) #> [13:58:14.814] on.exit(options(oopts), add = TRUE) #> [13:58:14.814] } #> [13:58:14.814] { #> [13:58:14.814] lapply(seq_along(...future.elements_ii), FUN = function(jj) { #> [13:58:14.814] ...future.X_jj <- ...future.elements_ii[[jj]] #> [13:58:14.814] assign(".Random.seed", ...future.seeds_ii[[jj]], #> [13:58:14.814] envir = globalenv(), inherits = FALSE) #> [13:58:14.814] ...future.FUN(...future.X_jj, ...) #> [13:58:14.814] }) #> [13:58:14.814] } #> [13:58:14.814] }, args = future.call.arguments) #> [13:58:14.814] } #> [13:58:14.814] Lazy evaluation: FALSE #> [13:58:14.814] Asynchronous evaluation: FALSE #> [13:58:14.814] Local evaluation: TRUE #> [13:58:14.814] Environment: 0x5572e9181490 #> [13:58:14.814] Capture standard output: TRUE #> [13:58:14.814] Capture condition classes: ‘condition’ (excluding ‘nothing’) #> [13:58:14.814] Globals: 5 objects totaling 35.81 KiB (DotDotDotList ‘future.call.arguments’ of 0 bytes, function ‘...future.FUN’ of 35.45 KiB, list ‘...future.elements_ii’ of 160 bytes, list ‘...future.seeds_ii’ of 160 bytes, numeric ‘...future.globals.maxSize’ of 56 bytes) #> [13:58:14.814] Packages: <none> #> [13:58:14.814] L'Ecuyer-CMRG RNG seed: <none> (seed = NULL) #> [13:58:14.814] Resolved: TRUE #> [13:58:14.814] Value: 160 bytes of class ‘list’ #> [13:58:14.814] Early signaling: FALSE #> [13:58:14.814] Owner process: 9d04a638-80d7-2cb1-c9c4-7dbd6de2ef73 #> [13:58:14.814] Class: ‘SequentialFuture’, ‘UniprocessFuture’, ‘Future’, ‘environment’
#> [13:58:14.816] Chunk #1 of 1 ... DONE
#> [13:58:14.816] Launching 1 futures (chunks) ... DONE
#> [13:58:14.816] Resolving 1 futures (chunks) ...
#> [13:58:14.816] - Number of value chunks collected: 1
#> [13:58:14.816] Resolving 1 futures (chunks) ... DONE
#> [13:58:14.817] Reducing values from 1 chunks ...
#> [13:58:14.817] - Number of values collected after concatenation: 2
#> [13:58:14.817] - Number of values expected: 2
#> [13:58:14.817] Reducing values from 1 chunks ... DONE
#> [13:58:14.817] future_lapply() ... DONE
print(Y2)
#> [,1] [,2] #> [1,] 7 6 #> [2,] 1 8 #> [3,] 3 4 #> [4,] 1 2
stopifnot(all.equal(Y1, Y2)) # } # \dontshow{ ## R CMD check: make sure any open connections are closed afterward if (!inherits(plan(), "sequential")) plan(sequential) # }