Merck / metalite

An R package to create metadata structure for ADaM data analysis and reporting
https://merck.github.io/metalite/
GNU General Public License v3.0
15 stars 5 forks source link

Tests fail when running with `devtools::test()` #159

Closed nanxstats closed 7 months ago

nanxstats commented 7 months ago

It looks like devtools::test() is more rigorous on namespace and evaluation than how tests are ran under R CMD check:

── Failed tests ─────────────────────────────────
Error (test-independent-testing-meta_run.R:15:3): all analysis based on the analysis plan would be executed
Error in `ae_summary(meta = meta, population = "apat", observation = "wk12", 
    parameter = "any;rel;ser")`: could not find function "ae_summary"
Backtrace:
    ▆
 1. ├─testthat::expect_equal(class(meta_run(meta)), "list") at test-independent-testing-meta_run.R:15:3
 2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─metalite::meta_run(meta)
 5.   └─base::lapply(call, function(x) eval(parse(text = x))) at metalite/R/meta_run.R:45:3
 6.     └─metalite (local) FUN(X[[i]], ...)

Error (test-independent-testing-meta_run.R:19:3): only the first analysis based on the analysis plan would be executed
Error in `ae_summary(meta = meta, population = "apat", observation = "wk12", 
    parameter = "any;rel;ser")`: could not find function "ae_summary"
Backtrace:
    ▆
 1. ├─testthat::expect_equal(class(meta_run(meta, i = 1)), "list") at test-independent-testing-meta_run.R:19:3
 2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─metalite::meta_run(meta, i = 1)
 5.   └─base::lapply(call, function(x) eval(parse(text = x))) at metalite/R/meta_run.R:45:3
 6.     └─metalite (local) FUN(X[[i]], ...)

Error (test-independent-testing-meta_run.R:23:3): selected analysis based on the analysis plan would be executed
Error in `ae_summary(meta = meta, population = "apat", observation = "wk12", 
    parameter = "any;rel;ser")`: could not find function "ae_summary"
Backtrace:
    ▆
 1. ├─testthat::expect_equal(...) at test-independent-testing-meta_run.R:23:3
 2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. └─metalite::meta_run(meta, i = c(1, 3, 5))
 5.   └─base::lapply(call, function(x) eval(parse(text = x))) at metalite/R/meta_run.R:45:3
 6.     └─metalite (local) FUN(X[[i]], ...)

[ FAIL 3 | WARN 0 | SKIP 0 | PASS 257 ]
nanxstats commented 7 months ago

It turns out these functions need to be available from the global environment to work.

As a simple solution, I move them into the standard location tests/testthat/helper.R and use <<- when defining them.