inst/testme/test-futurize-sandwich.R

#' @tags pkg-sandwich
if (requireNamespace("sandwich") && requireNamespace("future.apply")) {
library(futurize)
library(sandwich)
fcns <- tryCatch({
  futurize::futurize_supported_functions("sandwich")
}, error = identity)
print(fcns)
stopifnot(is.character(fcns), length(fcns) > 0L)
options(future.rng.onMisuse = "error")

plan(multisession, workers = 2L)

RNGkind("L'Ecuyer-CMRG")

fm <- lm(dist ~ speed, data = cars)

## Truth (sequential lapply)
## Since the non-parallel version uses a different set of RNG seeds
## than the parallel versions, we will not get numerically identical
## results
#set.seed(42)
#vcov_truth <- sandwich::vcovBS(fm, R = 5L)

## futurize()
set.seed(42)
vcov <- sandwich::vcovBS(fm, R = 5L) |> futurize()

stopifnot(
  is.matrix(vcov),
  all(dim(vcov) == c(2, 2))
)

## vcovJK()
set.seed(42)
vcov_jk <- sandwich::vcovJK(fm) |> futurize()
stopifnot(
  is.matrix(vcov_jk),
  all(dim(vcov_jk) == c(2, 2))
)

plan(sequential)
}

Try the futurize package in your browser

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

futurize documentation built on Oct. 20, 2026, 1:06 a.m.