title: How do I save R code using code in R Studio
body: <p>I am looking for a way to 'auto save' my code each time i run it.  I figure the best way to achieve this would be to write code in my models which will overwrite and save the file which is open. I have been experimenting with:</p>
  <pre><code>rstudioapi::documentSave(rstudioapi::getActiveDocumentContext()$id)
  </code></pre>
  <p>However, I have not had any success.</p>