title: how to automate series of scripts in R
body: <p>I am working with series of R scripts which required to run 100 times for 100 files. I am trying but couldn't able to do the task smoothly.</p>
  <p>My initial command was :</p>
  <pre><code>a1 &lt;- data2haplohh(hap_file=&quot;file1.csv&quot;, polarize_vcf=FALSE)
  </code></pre>
  <p>followed by :</p>
  <pre><code>a2&lt;-subset(a1, min_maf=0.05)
  </code></pre>
  <p>followed by :</p>
  <pre><code>a3&lt;-scan_hh(a2, polarized=FALSE)
  </code></pre>
  <p>followed with:</p>
  <pre><code>a4&lt;-ihh2ihs(a3, freqbin=100)
  write.csv(a4, &quot;newa.csv&quot;)
  </code></pre>
  <p>I tried this but it only works for first 2 steps and through error when adding a3 onwards.</p>
  <pre><code>list2env(
  setNames(
      lapply(
          seq(100),
          function(i) {
              subset(
                  data2haplohh(hap_file = sprintf(&quot;file%s.csv&quot;, i), polarize_vcf = FALSE),
                  min_maf = 0.05
              )
          }
      ), 
      paste0(&quot;a&quot;, seq(100))
  ),
  envir = .GlobalEnv
  )
  </code></pre>
  <p>Can you help me in setting up the script. It take long long time to run manually.
  Thankyou</p>