title: How to initialize libraries by their string names in cluster?
body: <p>I want to initialize libraries in cluster by their names represented as strings.</p>
  
  <p>This code works fine:</p>
  
  <pre><code>library(snowfall, rlecuyer, rsprng)
  sfInit(parallel = TRUE, cpus = 4, type = "SOCK")
  sfClusterEval(library(e1071))
  </code></pre>
  
  <p>And this code produces en error: <code>4 nodes produced errors; first error: object 'expr' not found</code></p>
  
  <pre><code>library(snowfall, rlecuyer, rsprng)
  sfInit(parallel = TRUE, cpus = 4, type = "SOCK")
  lib &lt;- "e1071"
  expr &lt;- parse(text=paste("library(", lib, ")", sep=""))
  sfClusterEval(expr)
  </code></pre>
  
  <p>So <code>sfClusterEval</code> try to evaluate <code>expr</code> and not an expression which <code>expr</code> contains. I cannot undestand which type of expression should be passed to <code>sfClusterEval</code> function, which uses <code>substitute</code> in its body</p>
  
  <pre><code>&gt; sfClusterEval
  function (expr, stopOnError = TRUE) 
  {
      sfCheck()
      if (sfParallel()) {
          return(sfClusterCall(eval, substitute(expr), env = globalenv(), 
              stopOnError = stopOnError))
      }
      else {
          return(eval(expr, envir = globalenv(), enclos = parent.frame()))
      }
  }
  </code></pre>
  
  <p>This question seems simple, but I could not solve it and need someone's advice.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Further investigation details on simplier examples. I feel that the truth is near.
  This code works fine</p>
  
  <pre><code>sfClusterEval(library("e1071"))
  </code></pre>
  
  <p>But this call produces en error: 4 nodes produced errors; first error: object 'lib' not found</p>
  
  <pre><code>lib &lt;- "e1071"
  sfClusterEval(library(lib, character.only=TRUE))
  </code></pre>
  
  <p><strong>ANSWER:</strong></p>
  
  <p>The variable <code>lib</code> should be exported to the cluster previously. And after that it can be removed.</p>
  
  <pre><code>lib &lt;- "e1071"
  sfExport("lib")
  sfClusterEval(library(lib, character.only=TRUE))
  sfRemove("lib")
  </code></pre>
  
  <p>Thanks for Richie, for giving the starting idea!</p>