title: Have an Rscript read or take input from stdin
body: <p>I see how to have an Rscript perform the operations I want when given a filename as an argument, e.g. if my Rscript is called <code>script</code> and contains:</p>
  
  <pre><code>#!/usr/bin/Rscript 
  path &lt;- commandArgs()[1]
  writeLines(readLines(path))
  </code></pre>
  
  <p>Then I can run from the bash command line:</p>
  
  <pre><code>Rscript script filename.Rmd --args dev='svg'
  </code></pre>
  
  <p>and successfully get the contents of <code>filename.Rmd</code> echoed back out to me.  If instead of passing the above argument a filename like <code>filename.Rmd</code> I want to pass it text from <code>stdin</code>, I try modifying my script to read from stdin:</p>
  
  <pre><code>#!/usr/bin/Rscript 
  writeLines(file("stdin"))
  </code></pre>
  
  <p>but I do not know how to construct the commandline call for this case.  I tried piping in the contents: </p>
  
  <pre><code>cat filename.Rmd | Rscript script --args dev='svg'
  </code></pre>
  
  <p>and also tried redirect: </p>
  
  <pre><code>Rscript script --args dev='svg' &lt; filename.Rmd
  </code></pre>
  
  <p>and either way I get the error:</p>
  
  <pre><code>Error in writeLines(file("stdin")) : invalid 'text' argument
  </code></pre>
  
  <p>(I've also tried <code>open(file("stdin"))</code>).  I'm not sure if I'm constructing the Rscript incorrectly, or the commandline argument incorrectly, or both. </p>