title: foreach %dopar% yielding “cannot find function” errors when the function to be parallelised is a list element
body: <p>I’ve successfully parallelised a function – let’s call it <code>AddOne</code> - via the <code>doParallel</code> package, <code>foreach</code> and <code>%dopar%</code> and I’m familiar with the <code>.packages</code> and <code>.export</code> arguments to <code>foreach</code>.</p>
  
  <p>My problem is that I would like <code>AddOne</code>, instead of being a “stand-alone” function, to be an element of a list and in this case, I can’t get things working. Specifically, if <code>AddOne</code> calls a subroutine <code>AddOneSubroutine</code> then <code>AddOneSubroutine</code> does not get found in the “worker” environments even though it is “exported”.</p>
  
  <p>I’m using Windows 10 and <code>R.version</code> yields:</p>
  
  <pre><code>platform       x86_64-w64-mingw32          
  arch           x86_64                      
  os             mingw32                     
  system         x86_64, mingw32             
  status                                     
  major          3                           
  minor          4.1                         
  year           2017                        
  month          06                          
  day            30                          
  svn rev        72865                       
  language       R                           
  version.string R version 3.4.1 (2017-06-30)
  nickname       Single Candle 
  </code></pre>
  
  <p>The doParallel version I have is 1.0.10.
  Here’s some code that demonstrates the problem as succinctly as I could.</p>
  
  <pre><code>library(doParallel)
  if(!exists("Registered")){
      registerDoParallel(cores = detectCores(logical = TRUE))
      Registered = TRUE
  }
  
  AddOne&lt;-function(x){AddOneSubroutine(x)}
  AddOneSubroutine &lt;-function(x){x+1}
  
  MyList&lt;-list()
  MyList$f&lt;-AddOne
  
  # Not using parallel environments, works correctly when calling AddOne 3 times
  Result1 = foreach(i = 1:3) %do% AddOne(i)
  Result1
  
  # Not using parallel environments, works correctly when calling MyList$f 3 times
  Result2 = foreach(i = 1:3) %do% MyList$f(i)
  Result2
  
  # Using parallel environments, works correctly when calling AddOne 3 times,
  # despite not explicitly using the .export argument to export AddOneSubroutine
  Result3 = foreach(i = 1:3) %dopar% AddOne(i)
  Result3
  
  # Using parallel environments, fails when calling MyList$f with error
  # "could not find function "AddOneSubroutine"", even though that function is "exported"
  Result4 = foreach(i = 1:3,.export = "AddOneSubroutine") %dopar% MyList$f(i)
  Result4
  </code></pre>
  
  <p>What am I failing to understand?</p>