title: Is it a bad idea to get name of script using sys.frame(1)$ofile?
body: <p>I've been searching for a while for a way to get the name of the currently executed script.  Most answers I've seen were one of:</p>
  
  <ol>
  <li>Use <code>commandArgs()</code> - but this won't work for me because in RStudio <code>commandArgs()</code> does not return the filepath  </li>
  <li>Define the name of the script as the top line and then use that in the rest of the script</li>
  </ol>
  
  <p>I saw one mention of <code>sys.frames()</code> and found out that I can use <code>sys.frame(1)$ofile</code> to get the name of the currently executing script.  I don't know much about these kinds of functions, so can anyone advise me if that's a bad a idea or when it can fail me?</p>
  
  <p>Thanks</p>