by Hong Ooi, Senior Data Scientist at Microsoft and maintainer of the foreach package
This post is to announce some new and upcoming changes in the foreach package.
First, foreach can now be found on GitHub! The repository is at https://github.com/RevolutionAnalytics/foreach, replacing its old home on R-Forge. Right now the repo hosts both the foreach and iterators packages, but that may change later.
The latest 1.4.8 version of foreach, which is now live on CRAN, adds preliminary support for evaluating
%dopar% expressions in a local environment when a sequential backend is used. This addresses a long-standing inconsistency in the behaviour of
%dopar% with parallel and sequential backends, where the latter would evaluate the loop body in the global environment by default. This is a common source of bugs: code that works when prototyped with a sequential backend, mysteriously fails with a “real” parallel backend.
From version 1.4.8, the behaviour of
%dopar% can be controlled with
or equivalently via the system environment variable
with the R option taking its value from the environment variable. The current default value is FALSE, which retains the pre-existing behaviour. It is intended that over time this will be changed to TRUE.
A side-effect of this change is that
%dopar% will (eventually) behave differently for a sequential backend. See this Github issue for more discussion on this topic.
In the background, the repo has also been updated to use modern tooling such as Roxygen, RMarkdown and testthat. None of these should affect how the package works, although there are some minor changes to documentation formats (in particular, the vignettes are now in HTML format rather than PDF).