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

Error in expect_equal for long arguments that use :: for method call #1472

Closed
const-ae opened this issue Oct 7, 2021 · 4 comments · Fixed by #1498
Closed

Error in expect_equal for long arguments that use :: for method call #1472

const-ae opened this issue Oct 7, 2021 · 4 comments · Fixed by #1498
Milestone

Comments

@const-ae
Copy link

const-ae commented Oct 7, 2021

In the latest version of testthat, a call to expect_equal() can produce an error in is_call_infix() because as far as I can tell is_call_infix expects x[[1]] to be a single element. The problem only occurs for very specific function calls:

  • the argument has to be very long so that deparse returns a vector with length > 1
  • the function call has to have exactly two arguments

See this reprex for a reproducible example:

Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "TRUE")
print(base::any(c(veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy_long_name = TRUE), na.rm=TRUE))
#> [1] TRUE
testthat::expect_equal(base::any(c(veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy_long_name = TRUE), na.rm=TRUE), TRUE)
#> Error in name %in% base || grepl("^%.*%$", name): 'length(x) = 3 > 1' in coercion to 'logical(1)'

Created on 2021-10-07 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.1.1 (2021-08-10)
#>  os       macOS Big Sur 10.16         
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Berlin               
#>  date     2021-10-07                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.1.0)
#>  cli           3.0.1   2021-07-17 [1] CRAN (R 4.1.0)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.1.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.0)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
#>  knitr         1.34    2021-09-09 [1] CRAN (R 4.1.1)
#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.1.0)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
#>  pillar        1.6.2   2021-07-29 [1] CRAN (R 4.1.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.0)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.1.0)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
#>  stringi       1.7.4   2021-08-25 [1] CRAN (R 4.1.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.5.1   2021-07-13 [1] CRAN (R 4.1.0)
#>  testthat      3.1.0   2021-10-04 [1] CRAN (R 4.1.0)
#>  tibble        3.1.4   2021-08-25 [1] CRAN (R 4.1.0)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.1.0)
#>  xfun          0.26    2021-09-14 [1] CRAN (R 4.1.1)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

Best, Constantin

@LTLA
Copy link

LTLA commented Oct 10, 2021

I was also wondering why some of my packages were failing on the BioC build machines, but not locally. After jogging my memory, I remembered that the BioC machines turn on _R_CHECK_LENGTH_1_LOGIC2_, leading to the failure above. In my case, it was for invocations for expect_true, but I suppose that anything calling testthat::is_call_infix() would be affected.

@rdiaz02
Copy link

rdiaz02 commented Oct 14, 2021

For completeness, I have just tested (in two different R 4.1.1 versions, svn rev 80725 and 80883) the exact same lines of code (see below) that triggered the error reported in #1470 (comment), with the settings

Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_" = "verbose")
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "verbose")

using testthat versions 3.0.4 and 3.1.1 . The code fails with version 3.1.1 but not with version 3.0.4.

Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_" = "verbose")
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "verbose")
library(testthat)
library(OncoSimulR)
packageVersion("testthat")

p5 <- cbind(c(0L), c(5L))
m5 <- matrix(0L, ncol = 6, nrow = 6); colnames(m5) <- rownames(m5) <- 0:5
m5[1, 2:6] <- 1L

expect_equal(
    OncoSimulR:::adjmat.to.restrictTable(
        OncoSimulR:::posetToGraph(p5, names = 1:5, addroot = FALSE, type = "adjmat"),
        root = FALSE),
    OncoSimulR:::adjmat.to.restrictTable(
        OncoSimulR:::posetToGraph(p5, names = 0:5, addroot = TRUE, type = "adjmat"),
        root = TRUE))

Note, though, that the failure under testthat version 3.1.1 does not happen with

Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_ "= "package:_R_CHECK_PACKAGE_NAME_,abort,verbose")
Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "package:_R_CHECK_PACKAGE_NAME_,abort,verbose")

and it seems that in the last couple of weeks BioC has changed back the settings of _R_CHECK_LENGTH_1_CONDITION_, _R_CHECK_LENGTH_1_LOGIC2_ to package:_R_CHECK_PACKAGE_NAME_,abort,verbose (I compared my version downloaded in 6-october with the current one from https://bioconductor.org/checkResults/devel/bioc-LATEST/Renviron.bioc, and those settings have changed).

@LTLA
Copy link

LTLA commented Oct 15, 2021

Yes, it was changed on Tuesday to keep the builds running until this issue is fixed; see here.

@hadley
Copy link
Member

hadley commented Oct 15, 2021

Plan is to fix this using a function in rlang developed specifically for this purpose; rlang 1.0.0 should be going to CRAN early next week so we'll hopefully get a fix out by the end of next week

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

Successfully merging a pull request may close this issue.

4 participants