title: Recursively send list variables to the global environment
body: <p>Consider the following nested list, <code>nest</code>.</p>
  
  <pre><code>nest &lt;- list(
      A = list(w = 1:5, x = letters[1:5]),
      B = list(y = 6:10, z = LETTERS[1:5])
  )
  </code></pre>
  
  <p>I'd like to send all the individual variables in <code>nest</code> to the global environment. That is, the lists <code>A</code> and <code>B</code>, and the vectors <code>w</code>, <code>x</code>, <code>y</code>, and <code>z</code> should all go to the global environment.  Here are a few of my tries along with their results.  Notice that all of these only send <em>some</em> of the variables to the global environment.</p>
  
  <pre><code>list2env(nest, .GlobalEnv)
  ls()
  # [1] "A"    "B"    "nest"
  list2env(unlist(nest, recursive = FALSE), .GlobalEnv)
  ls()
  # [1] "A.w"  "A.x"  "B.y"  "B.z"  "nest"
  lapply(nest, list2env, envir = .GlobalEnv)
  ls()
  # [1] "nest" "w"    "x"    "y"    "z"   
  with(nest, list2env(mget(ls()), .GlobalEnv))
  ls()
  # [1] "A"    "B"    "nest"
  </code></pre>
  
  <p>I also tried other recursive possibilities and got errors because when <code>list2env</code> hits the bottom of the list, it finds that <code>x</code> is not a list.</p>
  
  <pre><code>rapply(nest, list2env, envir = .GlobalEnv)
  # Error in (function (x, envir = NULL, parent = parent.frame(), 
  #   hash = (length(x) &gt;  : first argument must be a named list
  with(nest, {
      obj &lt;- mget(ls())
      do.call(list2env, c(obj, envir = .GlobalEnv))
  })
  # Error in (function (x, envir = NULL, parent = parent.frame(), 
  #     hash = (length(x) &gt;  : unused arguments (A = list(w = 1:5, 
  #     x = c("a", "b", "c", "d", "e")), B = list(y = 6:10, 
  #     z = c("A", "B", "C", "D", "E")))
  </code></pre>
  
  <p>How can I recursively call <code>list2env</code> so that all variables go to the global environment?  From a fresh R session, <code>ls()</code> would result in</p>
  
  <pre><code># [1] "A" "B" "nest" "w" "x" "y" "z"
  </code></pre>
  
  <p>I've also experimented with <code>local</code> and am having the same problem.</p>