Jim Maas
Jim Maas

Reputation: 1729

.export many objects to R foreach

I've got an R script that runs on Linux, using openmpi, doMPI, and nested foreach loops to do some big simulations on ~ 300 cores, and it works quite well. Recently I've modulized the code into lots of individual .R files which are "sourced". However I still have to ".export" over 70 individual objects on the inside foreach loop. I've made several attempts to clean up the code by putting the names of all of these objects in a separate .R file, and then sourcing it. I also thought that

.export=c(ls())

might work, just export all objects to the cores but that didn't work either. Anyone know of a way of putting a list of object names in a file and passing the objects with those names to the cores? Thanks J

Upvotes: 1

Views: 1617

Answers (1)

F. Privé
F. Privé

Reputation: 11738

Use environments.

  • If you want to export the variables of the Global Environment, use .export = ls(globalenv()).
  • For the parent environment (calling function), use ls(parent.env()).
  • For the current environment (this should not be necessary), use ls(environment()).

Upvotes: 3

Related Questions