title: How can I run my script on several data directories
body: <p>I have create a R script that analyse and manipulate 2 different data frame extension, for exemple one task is to extract certain values from data and export it as a .txt file, here is part of my script and the data files that i use:</p>
  <pre><code>setwd('C:\\Users\\Zack\\Documents\\RScripts\\data\\data1')
  heat_data=&quot;data1.heat&quot;
  time =&quot;data1.timestamp&quot;
  ts_heat = read.table(heat_data)
  ts_heat = ts_heat[-1,]
  rownames(ts_heat) &lt;- NULL
  ts_time = read.table(time)
  back_heat = subset(ts_heat, V3 == 'H')
  back_time = ts_time$V1
  library(data.table)
  datDT[, newcol := fcoalesce(
  nafill(fifelse(track == &quot;H&quot;, back_time, NA_real_), type = &quot;locf&quot;),
  0)]
  last_heat = subset(ts_heat, V3 == 'H')
  last_time = last_heat$newcol
  x = back_time - last_heat
  dataest = data.frame(back_time , x)
  write_tsv(dataestimation, file=&quot;dataestimation.txt&quot;)
  </code></pre>
  <p>what i am looking for is to process my code to all my data files. For example here i am working in the path &quot;C:\Users\Zack\Documents\RScripts\data\blabladata1&quot; where data1 contain a .heat and . timestammp file. I want to process my script on blabladata2 (that contain also .heat and .timestamp), blabladata3 (that contain also .heat and .timestamp), blabladata4 ...etc
  So each file in the file: &quot;data&quot; contains this 2 .heat and .timestamp that i will use to export my dataestimation.txt. So in the end, each blabladata** should contain **.heat, **.timestamp, and dataestimation.txt that is filtered and calculated from the **.heat, **.timestamp files.</p>
  <p>I don't know if this problem is treatable with R or should I change my script to an 'argument' script and execute it using command lines by applying it to <code>'path'/data/*/.heat 'path'/data/*/.timestamp</code></p>