title: Convenience function for exporting objects to the global environment
body: <blockquote>
    <p><strong>UPDATE</strong>: I have added <a href="https://github.com/krlmlr/kimisc/blob/master/pkg/R/export.R" rel="nofollow noreferrer">a variant</a>
    of <a href="https://stackoverflow.com/a/17484932/946850">Roland's implementation</a> to the <a href="https://github.com/krlmlr/kimisc" rel="nofollow noreferrer">kimisc package</a>.</p>
  </blockquote>
  
  <p>Is there a convenience function for exporting objects to the global environment, which can be called from a function to make objects available globally?</p>
  
  <p>I'm looking for something like</p>
  
  <pre><code>export(obj.a, obj.b)
  </code></pre>
  
  <p>which would behave like</p>
  
  <pre><code>assign("obj.a", obj.a, .GlobalEnv)
  assign("obj.b", obj.b, .GlobalEnv)
  </code></pre>
  
  <h2>Rationale</h2>
  
  <p>I am aware of <code>&lt;&lt;-</code> and <code>assign</code>. I need this to refactor oldish code which is simply a concatenation of scripts:</p>
  
  <pre><code>input("script1.R")
  input("script2.R")
  input("script3.R")
  </code></pre>
  
  <p><code>script2.R</code> uses results from <code>script1.R</code>, and <code>script3.R</code> potentially uses results from both <code>1</code> and <code>2</code>. This creates a heavily polluted namespace, and I wanted to change each script</p>
  
  <pre><code>pollute &lt;- the(namespace)
  useful &lt;- result
  </code></pre>
  
  <p>to</p>
  
  <pre><code>(function() {
  pollute &lt;- the(namespace)
  useful &lt;- result
  export(useful)
  })()
  </code></pre>
  
  <p>as a first cheap countermeasure.</p>