Skip to content

WISH: Make it possible do undo a registerNnn() call #19

Description

@HenrikBengtsson

Background

Some package register dopar adaptors internally, e.g.

pkg_fcn <- function() {
  registerDoMC(4)
  ...
}

This, rather common, design pattern breaks whatever the user has previously set for whatever foreach purposes they have. For example, the following will not do what the user expects:

registerDoRedis()
y <- pkg_fcn()  ## <= silently registers another dopar adaptor
z <- foreach(x = 1:3) %dopar% { sqrt(x) }

Sometimes, these re-registrations happens deep down in the package dependency graphs making them really hard to locate.

Suggestion

Provide a way for package developers to temporarily register a dopar adapter using:

pkg_fcn <- function() {
  oldDoPar <- registerDoMC(4)
  on.exit(foreach::setDoPar(oldDoPar))
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions