title: How to keep track of input / output files in R
body: <p>I write many R scripts producing output that is later used as input to another R script. For example, I may write script <code>a.R</code>, save resulting table as an <code>a-result.rda</code> object, write script <code>b.R</code>, import the <code>a-result.rda</code> object, modify the table, maybe plot some graphs, save new table as <code>table.csv</code>, and so on..</p>
  
  <p>I find it cumbersome to identify the R script (here <code>a.R</code>) which the particular <code>table.csv</code> (indirectly) originated from.</p>
  
  <p>So far, my solution is a shortcut function in my <code>.bashrc</code> that allows me to pinpoint the immediate parent of an output object:</p>
  
  <pre><code>findinR(){ find . -iname '*.R' -exec grep -r $1 {} + ; }
  </code></pre>
  
  <p>If I am looking for the origin of <code>table.csv</code>, I can do <code>findinR table.csv</code>, and as output I will get the path of the <code>b.R</code> script, along with the corresponding <code>write.csv(..</code> line. Then, in <code>b.R</code> script I notice that <code>table.csv</code> is a modified version of <code>a-result.rda</code>, so I do <code>findinR a-result.rda</code> and I find script <code>a.R</code>. This is working for 'shallow' I/O dependencies, but makes me want to kill myself when dealing with more layers.</p>
  
  <p>Does anyone use/know of a text-based system or software that would allow me to produce (automatically or at least semi-automatically) I/O flowcharts or pipelines? So that I can record the history of the files generated during analysis?</p>
  
  <p><strong>EDIT:</strong> Some additional, potentially crucial details:</p>
  
  <ol>
  <li>I am not particularly interested in reporting tools or rerunning the entire analysis in one go (for smaller projects, I use <code>knitr</code>, but for more complex dependency-heavy workflows it's too cumbersome). I work with genomic data, which makes it impossible to rerun parts of the analysis. </li>
  <li>The input / output scripts/files have unstandardized names. I almost never repeat the same steps, so templates wouldn't help much.</li>
  <li>The final output can be anything, not only a <code>.csv</code> file, but most often it's <code>.rds</code> or <code>.rdata</code> / <code>.rda</code>.</li>
  <li>The only thing I need is a (semi-)automatics way to record the workflow, not necessarily rerun it with a different input. </li>
  </ol>
  
  <p><strong>EDIT2:</strong> I tried automatically generating txt files by grepping lines that incude <code>save()</code>, <code>load()</code>, <code>write.csv()</code>, <code>read.csv()</code>, <code>pdf()</code>, etc. However, I often use <code>paste</code> to generate my file names, so the corresponding lines in the code are not descriptive enough to be able to identify the file. </p>