title: How to write a testthat unit test for a function that returns a data frame
body: <p>I am writing a script that ultimately returns a data frame. My question is around if there are any good practices on how to use a unit test package to make sure that the data frame that is returned is correct. (I'm a beginning R programmer, plus new to the concept of unit testing)</p>
  
  <p>My script effectively looks like the following:</p>
  
  <pre><code># initialize data frame
  df.out &lt;- data.frame(...)
  
  # function set
  function1 &lt;- function(x) {...}
  function2 &lt;- function(x) {...}
  
  # do something to this data frame
  df.out$new.column &lt;- function1(df.out)
  
  # do something else
  df.out$other.new.column &lt;- function2(df.out)
  
  # etc ....
  </code></pre>
  
  <p>... and I ultimately end up with a data frame with many new columns. However, what is the best approach to test that the data frame that is produced is what is anticipated, using unit tests?</p>
  
  <p>So far I have created unit tests that check the results of each function, but I want to make sure that running all of these together produces what is intended. I've looked at <a href="http://r-pkgs.had.co.nz/tests.html" rel="noreferrer" title="Hadley Wickham&#39;s testing page">Hadley Wickham's page on testing</a> but can't see anything obvious regarding what to do when returning data frames. </p>
  
  <p>My thoughts to date are:</p>
  
  <ul>
  <li>Create an expected data frame by hand</li>
  <li>Check that the output equals this data frame, using <code>expect_that</code> or similar</li>
  </ul>
  
  <p>Any thoughts / pointers on where to look for guidance? My Google-fu has let me down considerably on this one to date. </p>