title: How to run a (changing) JavaScript file within a loop in R?
body: <p>I am working in <code>R</code>, but I have a small <code>Phantom JS</code> script that opens and writes a webpage to a file (<code>scrape_webpages.js</code>). There are many webpages that I need to download, named in a standard format (i.e. <code>http://webpage.net/2018</code>), where the last part (the year) varies. The <code>Phantom JS</code> script takes two arguments that need to vary: the path where to save the webpage and the webpage address.</p>
  
  <p>Now I know how to make a loop and iterate over the range of years I need to generate addresses and paths in <code>R</code>. And I can run an individual <code>js</code> script from within <code>R</code> with the <code>system</code> function.</p>
  
  <p>But (how) can I include the <code>js</code> (with varying arguments) script in an <code>R</code> loop? Alternatively, the loop can be implemented within the <code>js</code> script itself, but I don't know how to do that.</p>
  
  <p>Thanks for your help.</p>
  
  <p>(N.B. I cannot do what the <code>js</code> script does directly in <code>R</code>)</p>