Hi J,

There's 2 approaches you could take here:

1. Define "func2" in the body of the foreach loop.
2. Explicitly pass the function to each worker process, using the ".export"
argument in the foreach function.

Good luck!

-Zach

On Sat, Jun 23, 2012 at 12:03 PM, James Maas (MED) <J.Maas@uea.ac.uk> wrote:

> Non expert here!
>
> I'm helping a friend re-write some code that involves nested functions, so
> it will run in parallel, and to do it using current methods it involves
> nesting a foreach loop in a function that is later called.  I'm using MPI,
> but have also tried it with SNOW and get the same
> error, which returns the following error
>
> Error in { : task 1 failed - "could not find function "func2""
>
> I googled and dug around and found where someone had suggested a "helper
> function" but that doesn't seem to
> be a solution either.  I'm guessing this has something to do with scoping?
>
> Is there a way to export a function so it becomes universal and available
> to all other functions including within a foreach loop?
>
> I've attached a toy model that demonstrates our structure.  There might be
> much more elegant ways to do it, or there might even be
> fundamental errors here.  Any suggestions how to overcome this problem?
>
> Thanks
>
> J
> ===============================
> Dr. Jim Maas
> University of East Anglia
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>
>

	[[alternative HTML version deleted]]

