title: How to access variables created outside an Rmpi requests?
body: <p>I am trying to use Rmpi for parallel processing for the first time. When calling a self-made function using the mpi.apply command, the code can't seem to access variables created prior to the execution of the command. Here is an example:</p>
  <pre><code>library(Rmpi)
  mpi.spawn.Rslaves()
  
  df1 &lt;- data.frame(&quot;x&quot; = 1:2, &quot;y&quot; = 1:2)
  df2 &lt;- data.frame(&quot;x&quot; = 2:3, &quot;y&quot; = 2:3)
  df3 &lt;- data.frame(&quot;x&quot; = 3:4, &quot;y&quot; = 3:4)
  df4 &lt;- data.frame(&quot;x&quot; = 4:5, &quot;y&quot; = 4:5)
  
  fun &lt;- function(x) {
    input &lt;- get(paste0(&quot;df&quot;, x)) 
    return(input)
  }
  
  array &lt;- 1:4
  MPIresults &lt;- mpi.apply(array, fun)
  </code></pre>
  <p>And I get the following error messages:</p>
  <pre><code>&lt;simpleError in get(paste0(&quot;df&quot;, x)): object 'df1' not found&gt;
  &lt;simpleError in get(paste0(&quot;df&quot;, x)): object 'df2' not found&gt;
  &lt;simpleError in get(paste0(&quot;df&quot;, x)): object 'df3' not found&gt;
  &lt;simpleError in get(paste0(&quot;df&quot;, x)): object 'df4' not found&gt;
  </code></pre>
  <p>Any idea on what I'm doing wrong here? Should I be using another MPI command instead of &quot;mpi.apply&quot; that considers prior variables?</p>
  <p>Thanks!</p>