title: Is there a testthat expect_* function for comparing two objects behavior?
body: <p>I am writing some unit tests for an R package using <code>testthat</code>. I would like to compare two objects where not all the details need to match, but they must maintain equivalence with respect to a set of functions of interest.</p>
  <p>For a simple example, I want to use something like</p>
  <pre class="lang-r prettyprint-override"><code>library(testthat)
  
  x &lt;- 1:4
  y &lt;- matrix(4:1, nrow=2)
  
  test_that(&quot;objects behave similarly&quot;, {
    expect_equal_applied(x, y, .fn=list(sum, prod))
  
    ## which would be shorthand for:
    ## expect_equal(sum(x), sum(y))
    ## expect_equal(prod(x), prod(y))
  })
  </code></pre>
  <p>In practice, <code>x</code> and <code>y</code> might be S3 objects, not simply base data structures.</p>
  <p>Obviously, this is simple to implement, but I'd prefer something idiomatic if already existing. So, the question is, <strong>does <code>testthat</code> implement an expect function like this?</strong></p>
  <p>Searching through the API, nothing struck me as fitting this description, but it seems like a natural pattern. Or maybe there is a reason why such a pattern is objectionable that I'm overlooking.</p>