forked from benjaminrich/vpcstats
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add snapshot tests for plot.tidyvpcobj
- Loading branch information
1 parent
87cd11f
commit 2307998
Showing
9 changed files
with
9,182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,876 changes: 1,876 additions & 0 deletions
1,876
tests/testthat/_snaps/plot/censored-plot-with-aql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,436 changes: 2,436 additions & 0 deletions
2,436
tests/testthat/_snaps/plot/censored-plot-with-bql-aql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,890 changes: 1,890 additions & 0 deletions
1,890
tests/testthat/_snaps/plot/censored-plot-with-bql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
891 changes: 891 additions & 0 deletions
891
tests/testthat/_snaps/plot/one-sided-strat-formula-with-facet-wrap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
895 changes: 895 additions & 0 deletions
895
tests/testthat/_snaps/plot/two-sided-strat-formula-with-facet-grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
get_os <- function(){ | ||
sysinf <- Sys.info() | ||
if (!is.null(sysinf)){ | ||
os <- sysinf['sysname'] | ||
if (os == 'Darwin') | ||
os <- "osx" | ||
} else { ## mystery machine | ||
os <- .Platform$OS.type | ||
if (grepl("^darwin", R.version$os)) | ||
os <- "osx" | ||
if (grepl("linux-gnu", R.version$os)) | ||
os <- "linux" | ||
} | ||
tolower(os) | ||
} | ||
|
||
test_that("plot.tidyvpcobj plots binning without stats", { | ||
testthat::skip_if_not(get_os() == "windows") | ||
testthat::skip_on_cran() | ||
|
||
obs_data <- obs_data[MDV == 0] | ||
sim_data <- sim_data[MDV == 0] | ||
obs_data$PRED <- sim_data[REP == 1, PRED] | ||
|
||
vpc <- observed(obs_data, x = TIME, y = DV) | ||
vpc <- simulated(vpc, sim_data, y = DV) | ||
vpc <- binning(vpc, bin = NTIME) | ||
|
||
options(warn = -1) | ||
vdiffr::expect_doppelganger("Bins without stats", | ||
plot(vpc)) | ||
|
||
vpc <- predcorrect(vpc, pred = PRED) | ||
vdiffr::expect_doppelganger("Bins ypc without stats", | ||
plot(vpc)) | ||
options(warn = 0) | ||
|
||
}) | ||
|
||
|
||
test_that("plot.tidyvpcobj plots censoring", { | ||
testthat::skip_if_not(get_os() == "windows") | ||
testthat::skip_on_cran() | ||
|
||
obs_data <- obs_data[MDV == 0] | ||
sim_data <- sim_data[MDV == 0] | ||
obs_data$LLOQ <- obs_data[, ifelse(STUDY == "Study A", 50, 25)] | ||
obs_data$ULOQ <- obs_data[, ifelse(STUDY == "Study A", 125, 100)] | ||
|
||
vpc <- observed(obs_data, x = TIME, y = DV) | ||
vpc <- simulated(vpc, sim_data, y = DV) | ||
vpc <- censoring(vpc, blq = DV < LLOQ, lloq = LLOQ, alq = DV > ULOQ, uloq = ULOQ) | ||
vpc <-stratify(vpc, ~ STUDY) | ||
vpc <- binning(vpc, bin = NTIME) | ||
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9)) | ||
|
||
options(warn = -1) | ||
vdiffr::expect_doppelganger("Censored plot with bql", | ||
plot(vpc, censoring.type = "blq")) | ||
|
||
vdiffr::expect_doppelganger("Censored plot with aql", | ||
plot(vpc, censoring.type = "alq")) | ||
|
||
vdiffr::expect_doppelganger("Censored plot with bql aql", | ||
plot(vpc, censoring.type = "both")) | ||
|
||
plot_list <- plot(vpc, censoring.type = "both", censoring.output = "list") | ||
testthat::expect_true(length(plot_list) == 3) | ||
testthat::expect_true(all(sapply(plot_list, ggplot2::is.ggplot))) | ||
|
||
plot_grid <- plot(vpc, censoring.type = "both", censoring.output = "grid", nrow = 1, ncol = 3) | ||
testthat::expect_true(inherits(plot_grid, "egg")) | ||
options(warn = 0) | ||
|
||
}) | ||
|
||
test_that("plot.tidyvpcobj plots stratified", { | ||
testthat::skip_if_not(get_os() == "windows") | ||
testthat::skip_on_cran() | ||
|
||
obs_data <- obs_data[MDV == 0] | ||
sim_data <- sim_data[MDV == 0] | ||
|
||
options(warn = -1) | ||
#two-sided strat formula | ||
vpc <- observed(obs_data, x = TIME, y = DV) | ||
vpc <- simulated(vpc, sim_data, y = DV) | ||
vpc <- stratify(vpc, GENDER ~ STUDY) | ||
vpc <- binning(vpc, bin = NTIME) | ||
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9), quantile.type = 6) | ||
|
||
vdiffr::expect_doppelganger("Two sided strat formula with facet_grid", | ||
plot(vpc)) | ||
|
||
#one-sided strat formula | ||
vpc <- observed(obs_data, x = TIME, y = DV) | ||
vpc <- simulated(vpc, sim_data, y = DV) | ||
vpc <- stratify(vpc, ~ GENDER + STUDY) | ||
vpc <- binless(vpc) | ||
vpc <- vpcstats(vpc, qpred = c(0.1, 0.5, 0.9), quantile.type = 6) | ||
|
||
vdiffr::expect_doppelganger("One sided strat formula with facet_wrap", | ||
plot(vpc)) | ||
options(warn = 0) | ||
}) | ||
|