title: Purrr: How to assign only one of the fitted models to an object in .GlobalEnv and also keep a list of the fitted models?
body: <p>I'm fitting multiple null models (say <code>null</code>) and an alternative model (<code>full</code>) simultaneously using <code>purrr</code> and <code>furrr</code>. I'm trying to extract some values from these fitted models and further process them. By way of doing so, I would also like to assign the computation results of <code>full</code> to an object in the global environment.</p>
  <p>Since each model consumes a lot of memory in my real computation, (1) I want to do such an assignment only for <code>full</code>, not for <code>null</code>s, and (2) I want to keep the workflow using <code>|&gt;</code> to avoid creating intermediate objects. Then, how should I assign the results of only one of the fit models to an object in .GlobalEnv, keeping the pipe workflow?</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  c(
    &quot;Days + (1 + Days | Subject)&quot;,
    &quot;(1 + Days | Subject)&quot;
  ) |&gt;
    set_names(
      nm = c(
        &quot;full&quot;,
        &quot;null&quot;
      )
    ) |&gt;
    map(
      ~ paste(&quot;Reaction ~ &quot;, .x)
    ) |&gt;
    map(
      as.formula
    ) |&gt;
    furrr::future_map(
      .options = furrr::furrr_options(seed = 1L),
      ~ lme4::lmer(
        formula = .x,
        lme4::sleepstudy
      )
    ) |&gt; ### Here, I want to assign `full` to an object in .Globalenv
      map(fixef) |&gt;
      map(as_tibble)
  
  ### Assignment method I was trying to insert before `map(fixef)`
    (
      \(fit)
      walk( #or `map_at(`
        .x = names(fit),
        #.at = 1,
        .f = ~ assign(
          x = .x,
          value = fit[[.x]],
          envir = .GlobalEnv
        )
      )
    )()
  </code></pre>