title: Can I use group_map or group_walk to iteratively export results?
body: <p>I want to iteratively process a master list of comparisons using group_walk() or group_map() as an alternative method to import batches of .csv files.</p>
  <p>I would like to input a dataset that looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Test Assay</th>
  <th>Var1</th>
  <th>Var2</th>
  <th>Freq</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Assay1</td>
  <td>neg</td>
  <td>neg</td>
  <td>19</td>
  </tr>
  <tr>
  <td>Assay1</td>
  <td>neg</td>
  <td>pos</td>
  <td>5</td>
  </tr>
  <tr>
  <td>Assay1</td>
  <td>pos</td>
  <td>neg</td>
  <td>8</td>
  </tr>
  <tr>
  <td>Assay1</td>
  <td>pos</td>
  <td>pos</td>
  <td>141</td>
  </tr>
  <tr>
  <td>Assay2</td>
  <td>neg</td>
  <td>neg</td>
  <td>25</td>
  </tr>
  <tr>
  <td>Assay2</td>
  <td>neg</td>
  <td>pos</td>
  <td>6</td>
  </tr>
  <tr>
  <td>Assay2</td>
  <td>pos</td>
  <td>neg</td>
  <td>17</td>
  </tr>
  <tr>
  <td>Assay2</td>
  <td>pos</td>
  <td>pos</td>
  <td>33</td>
  </tr>
  <tr>
  <td>Assay3</td>
  <td>neg</td>
  <td>neg</td>
  <td>99</td>
  </tr>
  <tr>
  <td>Assay3</td>
  <td>neg</td>
  <td>pos</td>
  <td>20</td>
  </tr>
  <tr>
  <td>Assay3</td>
  <td>pos</td>
  <td>neg</td>
  <td>5</td>
  </tr>
  <tr>
  <td>Assay3</td>
  <td>pos</td>
  <td>pos</td>
  <td>105</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to use the function epi_analysis and export a csv for each Test Assay (in this example Assay1, Assay2, and Assay3). So far I have:</p>
  <pre><code>#Make export directory
  check_create_dir &lt;- function(the_dir) {
    if (!dir.exists(the_dir)) {
      dir.create(the_dir, recursive = TRUE) } #Creates a directory if it doesn't already exist
  }
  
  the_dir_ex &lt;- &quot;data_generated/epidata&quot; #Name the new desired directory
  
  check_create_dir(the_dir_ex) #Make the directory if it doesn't already exist
  
  #Make function for the series of analyses
  epi_analysis &lt;- function(.x, the_dir){
    #Clean data
    dat2 &lt;- .x  %&gt;%
      select(c(Var1, Var2, Freq)) %&gt;%
      pivot_wider(Var1, names_from = Var2, values_from = Freq) %&gt;%
      remove_rownames %&gt;% 
      column_to_rownames( var = &quot;Var1&quot;) %&gt;% 
      as.matrix() 
    
    #Run tests
    rval &lt;- epi.tests(dat2, conf.level = 0.95)
    rkappa&lt;-epi.kappa(dat2)
    gwet &lt;- gwet.ac1.table(dat2)
    kappa2 &lt;- kappa2.table(dat2)
    
    #Export results
    hd &lt;- c('sensitivity', 'specificity', 'pfp', 'pfn', 'kappa', 'gwet', 'pabak')
    ests &lt;- c(round(rval$elements$sensitivity$est, digits = 3), 
              round(rval$elements$specificity$est, digits = 3), 
              round(rval$element$pfp$est, digits = 3), 
              round(rval$element$pfn$est, digits = 3), 
              round(kappa2$coeff.val, digits = 3), 
              round(gwet$coeff.val, digits = 3), 
              round(rkappa$pabak$est, digits = 3))
    cis &lt;- c(paste(round(rval$elements$sensitivity$lower, digits = 3), round(rval$elements$sensitivity$upper, digits = 3), sep = &quot;,&quot;), 
             paste(round(rval$elements$specificity$lower, digits = 3), round(rval$elements$specificity$upper, digits = 3), sep = &quot;,&quot;),
             paste(round(rval$element$pfp$lower, digits = 3), round(rval$element$pfp$upper, digits = 3), sep = &quot;,&quot;),  
             paste(round(rval$element$pfn$lower, digits = 3), round(rval$element$pfn$upper, digits = 3), sep = &quot;,&quot;), 
             kappa2$coeff.ci, 
             gwet$coeff.ci, 
             paste(round(rkappa$pabak$lower, digits = 3), round(rkappa$pabak$lower, digits = 3), sep = &quot;,&quot;))
    
    df &lt;- data.frame(hd, ests, cis)
    
    write.csv(df, 
              file = paste0(the_dir, &quot;/&quot;, basename(.x$TestAssay)),
              na = &quot;999.99&quot;, 
              row.names = FALSE)
    
  }
  
  
  #Use group_map or group_walk to iterate through the different assays in the dataset.
  
  data &lt;- read_csv(&quot;data_raw/EpiTest.csv&quot;) %&gt;%
    group_by(TestAssay)%&gt;%
    group_map(~ epi_analysis)
  </code></pre>
  <p>But there are no csvs in my epidata folder. Any suggestions/corrections welcomed.</p>