inst/testme/test-future.apply-future_replicate.R

if (requireNamespace("future.apply", quietly = TRUE)) {

library(futurize)

message("*** future_replicate() ...")

for (strategy in supportedStrategies()) {
  message(sprintf("*** strategy = %s ...", sQuote(strategy)))
  plan(strategy)
  
  y0 <- replicate(5L, sample(10L, size = 1L))
  y1 <- replicate(5L, sample(10L, size = 1L)) |> futurize()
  stopifnot(length(y0) == length(y1))
  
  set.seed(0xBEEF)
  y1 <- replicate(5L, sample(10L, size = 1L)) |> futurize()
  set.seed(0xBEEF)
  y2 <- replicate(5L, sample(10L, size = 1L)) |> futurize()
  stopifnot(all.equal(y2, y1))
  
  y3 <- replicate(5L, sample(10L, size = 1L)) |> futurize(seed = 0xBEEF)
  y4 <- replicate(5L, sample(10L, size = 1L)) |> futurize(seed = 0xBEEF)
  stopifnot(all.equal(y4, y3))
  
  
  message("- example(replicate) ...")
  
  foo <- function(x = 1, y = 2) c(x, y)
  bar0 <- function(n, x) replicate(n, foo(x = x))
  y0 <- bar0(5, x = 3)
  
  bar1 <- function(n, x) replicate(n, foo(x = x)) |> futurize()
  y1 <- bar1(5, x = 3)
  stopifnot(all.equal(y1, y0))
  
  plan(sequential)
  message(sprintf("*** strategy = %s ... done", sQuote(strategy)))
} ## for (strategy in ...) 

message("*** future_replicate() ... DONE")



} ## if (requireNamespace("future.apply", quietly = TRUE))

Try the futurize package in your browser

Any scripts or data that you put into this service are public.

futurize documentation built on March 19, 2026, 1:07 a.m.