Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.data.table problem with test_package #933

Closed
tdhock opened this issue Sep 4, 2019 · 2 comments
Closed

[.data.table problem with test_package #933

tdhock opened this issue Sep 4, 2019 · 2 comments

Comments

@tdhock
Copy link

tdhock commented Sep 4, 2019

the [.data.frame method seems to be incorrectly called when using [ on a data.table during test_package (but not test_file), which results in an "object not found" error.

I expected that tests should pass using both test_package and test_file, but tests only pass using test_file.

the code to reproduce the error is:

devtools::install_github("tdhock/testdtbug")
testthat::test_package("testdtbug")
testthat::test_file(system.file("tests", "testthat", "test-dt.R", package="testdtbug"))
devtools::session_info()

The output on my system was:

> devtools::install_github("tdhock/testdtbug")
Downloading GitHub repo tdhock/testdtbug@masterchecking for file/private/var/folders/7j/bq7gdv517tv9bb54j2tfnt3w0000gn/T/Rtmp7kTjTQ/remotes50377f7efd42/tdhock-testdtbug-e7a14c5/DESCRIPTION’ (533ms)
─  preparingtestdtbug:checking DESCRIPTION meta-informationchecking for LF line-endings in source and make fileschecking for empty or unneeded directoriescreating default NAMESPACE filebuildingtestdtbug_2019.9.3.tar.gz* installing *source* packagetestdtbug...
** help
No man pages found in packagetestdtbug*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (testdtbug)
> testthat::test_file(system.file("tests", "testthat", "test-dt.R", package="testdtbug"))
✔ |  OK F W S | Context|   2       | dt

══ Results ═════════════════════════════════════════════════════════════════════
OK:       2
Failed:   0
Warnings: 0
Skipped:  0
> testthat::test_package("testdtbug")
── 1. Error: dt [ method ok (@test-dt.R#5)  ────────────────────────────────────
objet 'foo' introuvable
1: data.table(group = 1:2, foo = "bar")[, {
       expect_identical(foo, "bar")
   }, by = group] at /Users/maudelaperriere/toby/R/testdtbug/tests/testthat/test-dt.R:5
2: `[.data.table`(data.table(group = 1:2, foo = "bar"), , {
       expect_identical(foo, "bar")
   }, by = group) at /Users/maudelaperriere/toby/R/testdtbug/tests/testthat/test-dt.R:5
3: `[.data.frame`(x, i, j)
4: expect_identical(foo, "bar") at /Users/maudelaperriere/toby/R/testdtbug/tests/testthat/test-dt.R:6
5: quasi_label(enquo(object), label, arg = "object")
6: eval_bare(get_expr(quo), get_env(quo))

══ testthat results  ═══════════════════════════════════════════════════════════
[ OK: 0 | SKIPPED: 0 | WARNINGS: 0 | FAILED: 1 ]
1. Error: dt [ method ok (@test-dt.R#5) 

Erreur : testthat unit tests failed
> devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 os       OS X Mavericks 10.9.5       
 system   x86_64, darwin13.4.0        
 ui       X11                         
 language (EN)                        
 collate  fr_CA.UTF-8                 
 ctype    fr_CA.UTF-8                 
 tz       America/Phoenix             
 date     2019-09-04Packages ───────────────────────────────────────────────────────────────────
 ! package      * version  date       lib source                           
   assertthat     0.2.1    2019-03-21 [1] CRAN (R 3.3.3)                   
   backports      1.1.4    2019-04-10 [1] CRAN (R 3.3.3)                   
   callr          3.3.1    2019-07-18 [1] CRAN (R 3.3.3)                   
   cli            1.1.0    2019-03-19 [1] CRAN (R 3.3.3)                   
   crayon         1.3.4    2017-09-16 [1] CRAN (R 3.3.2)                   
   curl           4.0      2019-07-22 [1] CRAN (R 3.3.3)                   
   data.table   * 1.12.2   2019-04-07 [1] CRAN (R 3.3.3)                   
   desc           1.2.0    2018-05-01 [1] CRAN (R 3.3.3)                   
   devtools       2.1.0    2019-07-06 [1] CRAN (R 3.3.3)                   
 V digest         0.6.13   2019-07-04 [1] CRAN (R 3.3.3)                   
   fs             1.3.1    2019-05-06 [1] CRAN (R 3.3.3)                   
   glue           1.3.1    2019-03-12 [1] CRAN (R 3.3.3)                   
   htmltools      0.3.6    2017-04-28 [1] CRAN (R 3.3.2)                   
   htmlwidgets    1.3      2018-09-30 [1] CRAN (R 3.3.3)                   
   magrittr       1.5      2014-11-22 [1] CRAN (R 3.3.0)                   
   memoise        1.1.0    2017-04-21 [1] CRAN (R 3.3.2)                   
   namedCapture   2019.8.9 2019-08-14 [1] local                            
 P nc           * 2019.9.3 2019-09-04 [?] local                            
 V pkgbuild       1.0.3    2019-08-26 [1] CRAN (R 3.3.3)                   
   pkgload        1.0.2    2018-10-29 [1] CRAN (R 3.3.3)                   
   prettyunits    1.0.2    2015-07-13 [1] CRAN (R 3.3.0)                   
   processx       3.4.1    2019-07-18 [1] CRAN (R 3.3.3)                   
   ps             1.3.0    2018-12-21 [1] CRAN (R 3.3.3)                   
   R6             2.4.0    2019-02-14 [1] CRAN (R 3.3.3)                   
   Rcpp           1.0.2    2019-07-25 [1] CRAN (R 3.3.3)                   
   RcppParallel   4.4.3    2019-05-22 [1] CRAN (R 3.3.3)                   
   re2r           0.2.0    2017-09-04 [1] CRAN (R 3.3.2)                   
   remotes        2.1.0    2019-06-24 [1] CRAN (R 3.3.3)                   
 V rlang          0.4.0    2019-09-04 [1] Github (r-lib/rlang@15e799c)     
   rprojroot      1.3-2    2018-01-03 [1] CRAN (R 3.3.2)                   
   rstudioapi     0.10     2019-03-19 [1] CRAN (R 3.3.3)                   
   sessioninfo    1.1.1    2018-11-05 [1] CRAN (R 3.3.3)                   
   stringi        1.4.3    2019-03-12 [1] CRAN (R 3.3.3)                   
 P testdtbug    * 2019.9.3 2019-09-04 [?] Github (tdhock/testdtbug@e7a14c5)
 V testthat     * 2.2.1    2019-09-04 [1] Github (r-lib/testthat@213d5ef)  
   usethis        1.5.1    2019-07-04 [1] CRAN (R 3.3.3)                   
   withr          2.1.2    2018-03-15 [1] CRAN (R 3.3.3)                   

[1] /Library/Frameworks/R.framework/Versions/3.3/Resources/library

 V ── Loaded and on-disk version mismatch.
 P ── Loaded and on-disk path mismatch.
> 

This also happens when running R --vanilla:

maudelaperriere@mbpdemaperriere:~/toby/r/testdtbug(master)$ LANG=EN R --vanilla -e 'testthat::test_package("testdtbug")'

R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
> testthat::test_package("testdtbug")
-- 1. Error: dt [ method ok (@test-dt.R#5)  ------------------------------------
object 'foo' not found
Backtrace:
 1. ...[] tests/testthat/test-dt.R:5:2
 4. testthat::expect_identical(foo, "bar") tests/testthat/test-dt.R:6:4
 5. testthat::quasi_label(enquo(object), label, arg = "object")
 6. rlang::eval_bare(expr, quo_get_env(quo))

== testthat results  ===========================================================
[ OK: 0 | SKIPPED: 0 | WARNINGS: 0 | FAILED: 1 ]
1. Error: dt [ method ok (@test-dt.R#5) 

Error: testthat unit tests failed
Execution halted
maudelaperriere@mbpdemaperriere:~/toby/r/testdtbug(master)$ LANG=EN R --vanilla -e 'testthat::test_file(system.file("tests", "testthat", "test-dt.R", package="testdtbug"));devtools::session_info()'

R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
> testthat::test_file(system.file("tests", "testthat", "test-dt.R", package="testdtbug"));devtools::session_info()
v |  OK F W S | Context
v |   2       | dt

== Results =====================================================================
Duration: 0.3 s

OK:       2
Failed:   0
Warnings: 0
Skipped:  0
- Session info ---------------------------------------------------------------
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 os       OS X Mavericks 10.9.5       
 system   x86_64, darwin13.4.0        
 ui       X11                         
 language (EN)                        
 collate  C                           
 ctype    C                           
 tz       America/Phoenix             
 date     2019-09-04                  

- Packages -------------------------------------------------------------------
 package     * version    date       lib source                         
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.3.3)                 
 backports     1.1.4      2019-04-10 [1] CRAN (R 3.3.3)                 
 callr         3.3.1      2019-07-18 [1] CRAN (R 3.3.3)                 
 cli           1.1.0      2019-03-19 [1] CRAN (R 3.3.3)                 
 crayon        1.3.4      2017-09-16 [1] CRAN (R 3.3.2)                 
 data.table  * 1.12.2     2019-04-07 [1] CRAN (R 3.3.3)                 
 desc          1.2.0      2018-05-01 [1] CRAN (R 3.3.3)                 
 devtools      2.1.0      2019-07-06 [1] CRAN (R 3.3.3)                 
 digest        0.6.20     2019-07-04 [1] CRAN (R 3.3.3)                 
 fs            1.3.1      2019-05-06 [1] CRAN (R 3.3.3)                 
 glue          1.3.1      2019-03-12 [1] CRAN (R 3.3.3)                 
 magrittr      1.5        2014-11-22 [1] CRAN (R 3.3.0)                 
 memoise       1.1.0      2017-04-21 [1] CRAN (R 3.3.2)                 
 pkgbuild      1.0.5      2019-08-26 [1] CRAN (R 3.3.3)                 
 pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.3.3)                 
 prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.3.0)                 
 processx      3.4.1      2019-07-18 [1] CRAN (R 3.3.3)                 
 ps            1.3.0      2018-12-21 [1] CRAN (R 3.3.3)                 
 R6            2.4.0      2019-02-14 [1] CRAN (R 3.3.3)                 
 Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.3.3)                 
 remotes       2.1.0      2019-06-24 [1] CRAN (R 3.3.3)                 
 rlang         0.4.0.9002 2019-09-04 [1] Github (r-lib/rlang@15e799c)   
 rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.3.2)                 
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.3.3)                 
 testthat    * 2.2.1.9000 2019-09-04 [1] Github (r-lib/testthat@213d5ef)
 usethis       1.5.1      2019-07-04 [1] CRAN (R 3.3.3)                 
 withr         2.1.2      2018-03-15 [1] CRAN (R 3.3.3)                 

[1] /Library/Frameworks/R.framework/Versions/3.3/Resources/library
> 
> 
maudelaperriere@mbpdemaperriere:~/toby/r/testdtbug(master)$ 
@tdhock
Copy link
Author

tdhock commented Sep 4, 2019

the relevant testthat code is

library(testthat)
library(data.table)

test_that("dt [ method ok", {
  data.table(group=1:2, foo="bar")[, {
    expect_identical(foo, "bar")
  }, by=group]
})

(from https://github.com/tdhock/testdtbug/blob/master/tests/testthat/test-dt.R)

@hadley
Copy link
Member

hadley commented Sep 4, 2019

This is almost certainly because of the way that data.table checks for whether or not it's in a data.table aware environment, and is unlikely to be directly related to testthat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants