1

I perform a major edit since I managed to narrow down the problem:

I encounter a new problem with devtools::test. My package used to pass unit test without any problem. But after updating my packages (including devtools and testthat) it now fails.

Reproducible example:

I have managed to build a reproducible example: In a new package architecture.

foo.R: a R file in /R/

foo <- function(obj){
  return(as.numeric(obj))
}

test_foo.R: a uniit test file in /tests/testthat

test_that("Test my foo function: ",
          {
            expect_true(is.na(foo("1,5")))
            })

testhat.R: to run my units tests in /tests/

library(testthat)
library(foo)
test_check("foo")

Two scenarios

Running: devtools::test()

> devtools::test()
Loading foo
Loading required package: testthat
Testing foo
√ | OK F W S | Context
Error in x[[method]](...) : attempt to apply non-function

== Results =====================================================================
Duration: 0.1 s

OK:       0
Failed:   4
Warnings: 1
Skipped:  0

Running testtjat::test_dir("tests/")

> testthat::test_dir("tests/")
√ | OK F W S | Context
== testthat results  ===========================================================
OK: 2 SKIPPED: 0 FAILED: 0

== Results =====================================================================
Duration: 0.1 s

OK:       0
Failed:   0
Warnings: 0
Skipped:  0

Environement

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] foo_0.0.0.9000 testthat_2.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.15     roxygen2_6.0.1   rprojroot_1.3-2  crayon_1.3.4     assertthat_0.2.0 digest_0.6.14    withr_2.1.1      commonmark_1.4  
 [9] R6_2.2.2         backports_1.1.2  magrittr_1.5     cli_1.0.0        rlang_0.1.6      stringi_1.1.6    rstudioapi_0.7   xml2_1.1.1      
[17] desc_1.1.1       devtools_1.13.4  tools_3.4.3      stringr_1.2.0    yaml_2.1.16      compiler_3.4.3   memoise_1.1.0   

NB:

An issue have been open on this matter on Github: https://github.com/hadley/devtools/issues/1675

Emmanuel-Lin
  • 1,848
  • 1
  • 16
  • 31
  • This question is 400% too long. Please put a clear succinct description of what the issue is on both the title and the first sentence. – smci Jan 19 '18 at 22:48
  • Thanks for your feed back, but I'm not quite sure on how to improve this question that necessitate to describe how i build muy package. Could you provide some advices? – Emmanuel-Lin Jan 22 '18 at 09:12
  • Well, *'I encounter a new problem with devtools::test"'* tells us almost nothing. Do you mean *"devtools::test started failing on my package (with X warning) since change Y"*? Or was it always failing? Or did it used to pass before `assertthat 0.2.0/ devtools 1.13.4` or some other package upgrade? (If so, roll back and tell us what package versions are known-good.) You seriously need to define what "I encounter a problem" means. In the first sentence. Also title. If those are unclear, you'll lose 90% of your audience on the first line. – smci Jan 22 '18 at 23:50
  • Move the code to below a clear concise description of the problem. Format it with code formatting. Use horizontal dividers to demarcate code from other section, for legibility. – smci Jan 22 '18 at 23:51

2 Answers2

0

When you are using data.table in your package, imports data.table in description is not enough. (note it should be imports, not import)

DESCRIPTION
Imports:
    data.table

This only ask your package user to have data.table package installed.

You will also need to add this

NAMESPACE
import(data.table)

Usually this is used to write function instead of pkg::function and is not suggested. However you have to do this for data.table.

Below is my explanation but it may not be totally accurate. I think it's because data.table need to dispatch some data.table specific functions for the implicit [] and other usage, which is not normal function call so you are not using something like data.table::rbindlist, and because the object is also a data.frame, the base version is called and caused problem.

This is a related question and answer.

dracodoc
  • 2,603
  • 1
  • 23
  • 33
  • Thanks for that, `imports` was a typo. I managed to narrow my problem down so I edited my question. It has in fact nothing to do with data.table. Sorry. – Emmanuel-Lin Jan 22 '18 at 12:41
0

This was a testhat issue, which was also raised on github https://github.com/r-lib/testthat/issues/700.

A solution was to put a context("some_string") at the beginning of each test file.

Emmanuel-Lin
  • 1,848
  • 1
  • 16
  • 31