registerDoFuture: Registers the future %dopar% backend

View source: R/registerDoFuture.R

registerDoFutureR Documentation

Registers the future %dopar% backend


Register the doFuture parallel adapter to be used by the foreach package.




Invisibly returns the previously registered foreach backend.

For package developers

Please refrain from modifying the foreach backend inside your packages / functions, i.e. do not call registerNnn() in your code. Instead, leave the control on what backend to use to the end user. This idea is part of the core philosophy of the foreach framework.

However, if you think it necessary to register the doFuture backend in a function, please make sure to undo your changes when exiting the function. This can be done using:

  oldDoPar <- registerDoFuture()
  on.exit(with(oldDoPar, foreach::setDoPar(fun=fun, data=data, info=info)), add = TRUE)

This is important because the end-user might have already registered a foreach backend elsewhere for other purposes and will most likely not known that calling your function will break their setup. Remember, your package and its functions might be used in a greater context where multiple packages and functions are involved and those might also rely on the foreach framework, so it is important to avoid stepping on others' toes.



doFuture documentation built on April 26, 2022, 5:07 p.m.