title: Programmatically determine if an R function is pure
body: <p>I'll paraphrase the definition of a pure function from a <a href="https://campus.datacamp.com/courses/writing-functions-in-r" rel="nofollow noreferrer">Datacamp course</a> by <a href="https://stackoverflow.com/users/16632/hadley">Hadley Wickham</a>:</p>
  
  <ul>
  <li>Outputs depend only on inputs</li>
  <li>Don't change anything outside the function
  
  <ul>
  <li>No setting of global variables, no plotting, no printing to console, etc</li>
  </ul></li>
  <li>Don't have any inputs that can be different for different users or sessions</li>
  </ul>
  
  <p>How can I determine if a particular function is pure in an automated fashion? I've thought about using <code>args()</code> to check for default values, but then I'm not sure how to check if the defaults are global values. And I've thought about checking which library a function comes from since some are known to contain mostly pure functions. But I don't think that's a test that works 100% of the time.</p>
  
  <p>Any partial answers would also be helpful. For example: How can I determine if a function creates a plot? How can I determine if a function prints to the console? I imagine one could design test cases, but showing many positive results and not finding a negative one is also not definitive proof.</p>