title: R: how do you merge/combine two environments?
body: <p>This is a simple question but the answer is apparently not so simple... Is it possible to combine environments in R?</p>
  
  <pre><code>E1 = new.env()
  E2 = new.env()
  E1$x = 25
  E2$y = 7
  </code></pre>
  
  <p>Ok, now I want an environment (say, <code>E3</code>) that has both <code>x</code> and <code>y</code> defined.</p>
  
  <pre><code>c(E1, E2)
  #doesn't work
  E3 = new.env(E1, E2)
  #doesn't work
  </code></pre>
  
  <p>I have found other <a href="https://stackoverflow.com/questions/12212503/merging-two-data-environments-and-do-call">similar questions</a> but they don't seem to work for me.</p>
  
  <p><strong>Use case:</strong> Maybe there's a reason this isn't easy...the reason I want to do this is thus: I use some functions to load up data. Previously, I've just loaded it into the global environment, but I now have many different functions loading different types of data (which I call variously as needed), and so I wanted to keep the loaded data a bit more compartmentalized. If I call 2 different loading functions <code>E1=loadData1()</code> and <code>E2=loadData2()</code>, and I now want to call a function that uses variables from both of these functions, I'd like to be able to say <code>with(E1 &amp; E2, someFunction())</code>. Hence, merging my loaded environments seems appropriate.</p>
  
  <p>So, what's the right way to merge them? And, as an aside, do you have a different suggestion for how to better accomplish what I'm doing, if merging environments is not the right way?</p>