R/addons-Sim.DiffProc.R

Defines functions append_transpilers_for_Sim.DiffProc

# Sim.DiffProc::MCM.sde(...) =>
#
# local({
#   cl <- future::makeClusterFuture(<future arguments>)
#   on.exit(options(oopts))
#   Sim.DiffProc::MCM.sde(..., parallel = "snow", ncpus = 2L, cl = cl)
# })
#
append_transpilers_for_Sim.DiffProc <- function() {
  if (getRversion() < "4.4.0") {
    stop(sprintf("You are running R %s, but futurization of 'Sim.DiffProc' functions requires R (>= 4.4.0)", getRversion()))
  }

  transpilers <- make_package_transpilers("Sim.DiffProc", FUN = function(fcn, name) {
    if ("cl" %in% names(formals(fcn))) {
      transpiler <- make_futurize_for_makeClusterFuture(
        args = list(
          parallel = "snow",
          ncpus = 2L,   ## only used for test ncpus > 1
          cl = quote(cl)
        ), defaults = list(
          packages = "Sim.DiffProc",
          seed = TRUE,
          label = sprintf("fz:Sim.DiffProc::%s", name)
        )
      )

      list(
        label = sprintf("Sim.DiffProc::%s() ~> Sim.DiffProc::%s(..., parallel = TRUE)", name, name),
        transpiler = transpiler
      )
    }
  })

  ## Register both generic and method calls
  transpiler_generic <- make_futurize_for_makeClusterFuture(
    args = list(
      parallel = "snow",
      ncpus = 2L,
      cl = quote(cl)
    ), defaults = list(
      packages = "Sim.DiffProc",
      seed = TRUE,
      label = "fz:Sim.DiffProc::MCM.sde"
    )
  )

  transpilers[["Sim.DiffProc"]][["MCM.sde"]] <- list(
    label = "Sim.DiffProc::MCM.sde() ~> Sim.DiffProc::MCM.sde(..., parallel = TRUE)",
    transpiler = transpiler_generic
  )

  append_transpilers("futurize::add-on", transpilers)

  ## Return required packages
  c("Sim.DiffProc", "future")
}

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.