Description Usage Arguments Value Author(s) Examples

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |

`X` |
an array, including a matrix. |

`MARGIN` |
A vector giving the subscripts which the function will be
applied over. For example, for a matrix |

`FUN` |
A function taking at least one argument. |

`simplify` |
a logical indicating whether results should be simplified if possible. |

`future.stdout` |
If |

`future.conditions` |
A character string of conditions classes to be
captured and relayed. The default is the same as the |

`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 |

`future.scheduling` |
Average number of futures ("chunks") per worker.
If |

`future.chunk.size` |
The average number of elements per future ("chunk").
If |

`future.label` |
If a character string, then each future is assigned
a label |

`...` |
(optional) Additional arguments passed to |

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.

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.

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 | ```
## ---------------------------------------------------------
## 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)
print(Y1)
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)
print(Y1)
stopifnot(all.equal(Y1, Y0))
## ---------------------------------------------------------
## Parallel Random Number Generation
## ---------------------------------------------------------
## 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)
print(Y1)
plan(sequential)
Y2 <- future_apply(X, MARGIN = 1L, FUN = sample, future.seed = 0xBEEF)
print(Y2)
stopifnot(all.equal(Y1, Y2))
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.