title: r - data.table and testthat package
body: <p>I am building a package which works with data.table and which should be tested using package testthat.
  While the code works fine when calling from the command line, I run into issues when calling from a test case. It seems that the [] function from the base package, i.e. the function for data.frames is used when running the tests.</p>
  
  <p>I have created a minimum example which can be found here: <a href="https://github.com/utalo/test_datatable_testthat" rel="noreferrer">https://github.com/utalo/test_datatable_testthat</a></p>
  
  <p>The package contains a single function:</p>
  
  <pre><code>test &lt;- function() {
     dt &lt;- data.table(MESSAGE="Test 1234567890",TYPE="ERROR")
     dt[,.(MESSAGE=strwrap(MESSAGE,width = 10)),by=.(TYPE)]
  }
  </code></pre>
  
  <p>When calling <code>test.datatable.testthat:::test()</code> from the command line I get the expected result:</p>
  
  <pre><code>    TYPE    MESSAGE
   1: ERROR       Test
   2: ERROR 1234567890
  </code></pre>
  
  <p>However, when executing the following unit test:</p>
  
  <pre><code>test_that("Test package",{
    dt &lt;- test()
  
    expected_res &lt;- structure(list(TYPE = c("ERROR", "ERROR"),
                               MESSAGE = c("Test","1234567890")),
                          row.names = c(NA, -2L), class = c("data.table","data.frame"),
                          .Names = c("TYPE", "MESSAGE"))
  
    expect_equal(dt,expected_res)
  })
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>1
  1. Error: Test package -------------------------------------------------------------------------------------------------------
  could not find function "."
  1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls, message = function(c) invokeRestart("muffleMessage"))
  2: eval(code, new_test_environment)
  3: eval(expr, envir, enclos)
  4: test() at test.R:4
  5: dt[, .(MESSAGE = strwrap(MESSAGE, width = 10)), by = .(TYPE)] at test.datatable.testthat/R/hello.R:5
  6: `[.data.table`(dt, , .(MESSAGE = strwrap(MESSAGE, width = 10)), by = .(TYPE)) at C:\Users\D057806\Documents\R\test.datatable.testthat/R/hello.R:5
  7: `[.data.frame`(x, i, j)
  </code></pre>
  
  <p>As you can see, within the test the [] of data.frame is called.
  My first guess was that the dependency to the data.table package is not declared correctly. This is my DESCRIPTION file:</p>
  
  <pre><code>Package: test.datatable.testthat
  Type: Package
  Title: What the Package Does (Title Case)
  Version: 0.1
  Date: 2016-04-07
  Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
  Description: More about what it does (maybe more than one line)
  License: What license is it under?
  LazyData: TRUE
  Depends:
      data.table
  Suggests:
       testthat
  RoxygenNote: 5.0.1
  </code></pre>
  
  <p>According to <a href="https://stackoverflow.com/questions/10527072/using-data-table-package-inside-my-own-package">Using data.table package inside my own package</a> it should be sufficient to declare data.table as a dependent package. However, this does not seem to be the case here.</p>
  
  <p>Any clues as to why my function is working when being called directly but not in the context of testthat?</p>