title: doParallel with own created functions
body: <p>I have created a sequential simulation in R to iterate a process 10,0000 times. This takes ~70 minutes and so I decided to try the same thing in parallel with the doParallel package.</p>
  
  <p>My foreach loop calls on a function called 'inv.predict' that is not in any existing package. When I run the code I get an error.</p>
  
  <pre><code>cl &lt;- makeCluster(4)
  registerDoParallel(cl)
  ptm &lt;- proc.time()
  clupeaformis_cr &lt;- foreach(i = 1:100, .packages = c("spider", "investr", "mgcv")) %dopar% {
  clupeaformis_cr &lt;- rep(NA,  i)
  clupeaformis_haplo_rand &lt;- haploAccum(clupeaformis_aligned, method = "random", permutations = 1000) 
  
  N &lt;- clupeaformis_haplo_rand$sequences
  H &lt;- clupeaformis_haplo_rand$n.haplotypes
  d &lt;- data.frame(N, H)
  
  clupeaformis_cr &lt;- gam(H ~ s(N, bs = "cr", k = 20), optimizer = c("outer", "bfgs"), data = d)
  clupeaformis_cr[i] &lt;- inv.predict(clupeaformis_cr, y = 21, x.name = "N", interval = TRUE, 
                 lower = 1, upper = 1000000)      
  }
  
  proc.time() - ptm
  stopCluster(cl)
  
  
  Error in { : 
     task 1 failed - "no applicable method for 'inv.predict' applied to an object of class "c('gam', 'glm', 'lm')""
  </code></pre>
  
  <p>I am unsure as to why this doesn't work in parallel but it does in a regular for loop. This question is related to another one that I posted yesterday.</p>
  
  <p>Any assistance is warmly welcomed.</p>