Changes in the foreach package

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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, 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 %do% and %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).

Some further changes are also planned down the road, to better integrate foreach with the future package by Henrik Bengtsson. See this Github issue for further details.

Please feel free to leave comments, bug reports and pull requests at the foreach repo, or you can contact me directly at .

To leave a comment for the author, please follow the link and comment on their blog: Revolutions. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)