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

Update tests to run via devtools::test() #293

Closed
wants to merge 1 commit into from

Conversation

jdblischak
Copy link
Collaborator

The tests pass when executed via R CMD check, but I noticed problems when running via devtools::test()

First, the test file test-independent-gs_power_ahr.R calls functions from {gsDesign} but doesn't load it. devtools::test() doesn't run tests/testthat.R, so all required libraries need to be loaded in the test file.

devtools::test(filter = "ahr")
ℹ Testing gsDesign2| F W  S  OK | Context|          2 | developer-ahr [2.0s]
✔ |         76 | developer-gs_design_ahr [17.9s]
✔ |         56 | developer-gs_power_ahr [23.1s]
✔ |          4 | independent-gs_design_ahr [1.4s]
✔ |          7 | independent-gs_info_ahr [5.1s]
✖ | 1        0 | independent-gs_power_ahr
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-independent-gs_power_ahr.R:3:1): (code run outside of `test_that()`)
Error in `gsSurv(k = 2, test.type = 1, alpha = 0.025, beta = 0.2, astar = 0, 
    timing = 0.7, sfu = sfLDOF, sfupar = c(0), sfl = sfLDOF, 
    sflpar = c(0), lambdaC = log(2)/9, hr = 0.65, hr0 = 1, eta = 0.001, 
    gamma = c(6, 12, 18, 24), R = c(2, 2, 2, 6), S = NULL, T = NULL, 
    minfup = NULL, ratio = 1)`: could not find function "gsSurv"
──────────────────────────────────────────────────

══ Results ═══════════════════════════════════════
Duration: 50.2 s

── Failed tests ──────────────────────────────────
Error (test-independent-gs_power_ahr.R:3:1): (code run outside of `test_that()`)
Error in `gsSurv(k = 2, test.type = 1, alpha = 0.025, beta = 0.2, astar = 0, 
    timing = 0.7, sfu = sfLDOF, sfupar = c(0), sfl = sfLDOF, 
    sflpar = c(0), lambdaC = log(2)/9, hr = 0.65, hr0 = 1, eta = 0.001, 
    gamma = c(6, 12, 18, 24), R = c(2, 2, 2, 6), S = NULL, T = NULL, 
    minfup = NULL, ratio = 1)`: could not find function "gsSurv"

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 145 ]

Second, I noticed the following warnings:

devtools::test(filter = "fixed_design")
ℹ Testing gsDesign2| F W  S  OK | Context|   2      7 | independent-fixed_design [4.0s]
──────────────────────────────────────────────────
Warning (test-independent-fixed_design.R:130:3): RD
Unknown or uninitialised column: `theta`.
Backtrace:1. └─gsDesign2::fixed_design_rd(...) at test-independent-fixed_design.R:130:3
 2.   └─gsDesign2::gs_design_rd(...) at gsDesign2/R/fixed_design_rd.R:96:5
 3.     ├─x$theta at gsDesign2/R/gs_design_rd.R:207:5
 4.     └─tibble:::`$.tbl_df`(x, theta) at gsDesign2/R/gs_design_rd.R:207:5

Warning (test-independent-fixed_design.R:130:3): RD
Unknown or uninitialised column: `info`.
Backtrace:1. └─gsDesign2::fixed_design_rd(...) at test-independent-fixed_design.R:130:3
 2.   └─gsDesign2::gs_design_rd(...) at gsDesign2/R/fixed_design_rd.R:96:5
 3.     ├─x$info at gsDesign2/R/gs_design_rd.R:208:5
 4.     └─tibble:::`$.tbl_df`(x, info) at gsDesign2/R/gs_design_rd.R:208:5
──────────────────────────────────────────────────

══ Results ═══════════════════════════════════════
Duration: 4.5 s

[ FAIL 0 | WARN 2 | SKIP 0 | PASS 7 ]

These are caused by fixed_design_rd() calling gs_design_rd() with the default value of h1_spending = TRUE. I removed the warnings by setting h1_spending = FALSE. Though I don't know what the consequences were that gs_design_rd() was getting these empty values for theta and info. I also don't know why theta and info are not being returned by the earlier call to gs_info_rd().

gsDesign2/R/gs_design_rd.R

Lines 206 to 212 in 50067c4

if (h1_spending) {
theta1 <- x$theta
info1 <- x$info
} else {
theta1 <- 0
info1 <- x$info0
}

@jdblischak jdblischak requested a review from nanxstats December 13, 2023 18:42
@jdblischak jdblischak self-assigned this Dec 13, 2023
@nanxstats
Copy link
Collaborator

I think these are good findings. I'm not sure if it's appropirate for me to merge at the moment - would be better if you can talk to the author of this test and gs_design_rd() to confirm the original intention...

@jdblischak
Copy link
Collaborator Author

I'm not sure if it's appropirate for me to merge at the moment

I agree. I had continued investigating after I opened the PR. While my quick fix removed the warnings, I am concerned why gs_design_rd() is behaving like this. I'll replace this PR with an Issue

@jdblischak jdblischak closed this Dec 14, 2023
@jdblischak
Copy link
Collaborator Author

Replaced by Issue #296

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 this pull request may close these issues.

2 participants