title: How to clusterExport a function without its evaluation environment
body: <p>I am trying to use <code>parLapply</code> inside of another function not defined in the global environment. The worker function makes use of a list of <em>other</em> functions that I want to <code>clusterExport</code> beforehand, which are also not defined in the global environment. My problem is that both functions export their evaluation environments to the clusters, which are huge and not needed.</p>
  
  <p>Let us call the the worker function <code>workerFunction</code> and the function list <code>functionList</code>.</p>
  
  <pre><code>    workerFunction &lt;- function(i) {
          intermediateOutput &lt;- functionList[[i]](y)
          result &lt;- otherCalculations(intermediateOutput)
          return(result)    
      }
  
      library(parallel)
      cl &lt;- makeCluster(detectCores())
      environment(workerFunction) &lt;- .GlobalEnv
      environment(functionList) &lt;- .GlobalEnv
      clusterExport(cl, varlist=c("functionList", "y"), envir=.GlobalEnv)
      output &lt;- parLapply(cl, inputVector, workerFunction)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Error in get(name, envir = envir) (from &lt;text&gt;#53) : object 'functionList' not found
  </code></pre>
  
  <p>If I don´t set <code>environment(functionList) &lt;- .GlobalEnv</code>, then the huge enclosing environment of <code>functionList</code> is exported to the clusters. Why can´t R find <code>functionList</code> in the global environment?</p>