diff --git a/R/meta_run.R b/R/meta_run.R index 8ff3f6b..60fdd4b 100644 --- a/R/meta_run.R +++ b/R/meta_run.R @@ -27,15 +27,17 @@ #' @export #' #' @examples -#' meta <- meta_example() -#' ae_summary <- function(...) { -#' paste("results of", deparse(match.call(), nlines = 1)) +#' if (interactive()) { +#' meta <- meta_example() +#' ae_summary <- function(...) { +#' "results of ae_summary" +#' } +#' ae_specific <- function(...) { +#' "results of ae_specific" +#' } +#' meta_run(meta) +#' meta_run(meta, i = 2) #' } -#' ae_specific <- function(...) { -#' paste("results of", deparse(match.call(), nlines = 1)) -#' } -#' meta_run(meta) -#' meta_run(meta, i = 2) meta_run <- function(meta, i = NULL, ...) { if (is.null(i)) i <- 1:nrow(meta$plan) call <- spec_call_program(meta, ...) diff --git a/R/meta_validate.R b/R/meta_validate.R index d6dc24e..6b137f7 100644 --- a/R/meta_validate.R +++ b/R/meta_validate.R @@ -40,6 +40,8 @@ meta_validate <- function(meta) { stop(".$plan must contain all required variable names: 'mock', 'analysis', 'population', 'observation', 'parameter'") } + meta$data_population + meta$population # Check id variable lapply(c(meta$population, meta$observation), function(x) { if (is.null(x$id)) { @@ -86,5 +88,17 @@ meta_validate <- function(meta) { } }) + # check group factor level are the same + u_plan <- unique(meta$plan[, c("population", "observation")]) + for (i in 1:nrow(u_plan)) { + key_pop <- u_plan[i, "population"] + key_obs <- u_plan[i, "observation"] + level_pop <- levels(meta$data_population[[metalite::collect_adam_mapping(meta, key_pop)$group]]) + level_obs <- levels(meta$data_observation[[metalite::collect_adam_mapping(meta, key_obs)$group]]) + if (!all(level_pop == level_obs)) { + stop("Inconsistent group level: the levels of group variable from population and observation datasets are not the same") + } + } + meta } diff --git a/man/meta_run.Rd b/man/meta_run.Rd index 2152a63..d82f35f 100644 --- a/man/meta_run.Rd +++ b/man/meta_run.Rd @@ -20,13 +20,15 @@ Executed analysis based on the analysis plan. Execute analysis based on the analysis plan } \examples{ -meta <- meta_example() -ae_summary <- function(...) { - paste("results of", deparse(match.call(), nlines = 1)) +if(interactive()){ + meta <- meta_example() + ae_summary <- function(...) { + "results of ae_summary" + } + ae_specific <- function(...) { + "results of ae_specific" + } + meta_run(meta) + meta_run(meta, i = 2) } -ae_specific <- function(...) { - paste("results of", deparse(match.call(), nlines = 1)) -} -meta_run(meta) -meta_run(meta, i = 2) } diff --git a/tests/testthat/_snaps/independent-testing-meta_run.md b/tests/testthat/_snaps/independent-testing-meta_run.md deleted file mode 100644 index e6fea2f..0000000 --- a/tests/testthat/_snaps/independent-testing-meta_run.md +++ /dev/null @@ -1,60 +0,0 @@ -# all analysis based on the analysis plan would be executed - - Code - meta_run(meta) - Output - $`ae_summary(meta = meta, population = 'apat', observation = 'wk12', parameter = 'any;rel;ser')` - [1] "results of ae_summary(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_summary(meta = meta, population = 'apat', observation = 'wk24', parameter = 'any;rel;ser')` - [1] "results of ae_summary(meta = meta, population = \"apat\", observation = \"wk24\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'any')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk24', parameter = 'any')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk24\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'aeosi')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk24', parameter = 'aeosi')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk24\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'rel')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk24', parameter = 'rel')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk24\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'ser')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk24', parameter = 'ser')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk24\", " - - -# only the first analysis based on the analysis plan would be executed - - Code - meta_run(meta, i = 1) - Output - $`ae_summary(meta = meta, population = 'apat', observation = 'wk12', parameter = 'any;rel;ser')` - [1] "results of ae_summary(meta = meta, population = \"apat\", observation = \"wk12\", " - - -# selected analysis based on the analysis plan would be executed - - Code - meta_run(meta, i = c(1, 3, 5)) - Output - $`ae_summary(meta = meta, population = 'apat', observation = 'wk12', parameter = 'any;rel;ser')` - [1] "results of ae_summary(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'any')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - $`ae_specific(meta = meta, population = 'apat', observation = 'wk12', parameter = 'aeosi')` - [1] "results of ae_specific(meta = meta, population = \"apat\", observation = \"wk12\", " - - diff --git a/tests/testthat/test-independent-testing-meta_run.R b/tests/testthat/test-independent-testing-meta_run.R index 25b9ce8..d09a43f 100644 --- a/tests/testthat/test-independent-testing-meta_run.R +++ b/tests/testthat/test-independent-testing-meta_run.R @@ -1,15 +1,24 @@ # Create example `meta_adam` object meta <- meta_example() -# Snapshot testing +ae_summary <- function(meta, population, observation, parameter) { + message("run ae_summary") + return(NULL) +} + +ae_specific <- function(meta, population, observation, parameter) { + message("run ae_specific") + return(NULL) +} + test_that("all analysis based on the analysis plan would be executed", { - expect_snapshot(meta_run(meta)) + expect_null(meta_run(meta)[[1]]) }) test_that("only the first analysis based on the analysis plan would be executed", { - expect_snapshot(meta_run(meta, i = 1)) + expect_null(meta_run(meta, i = 1)[[1]]) }) test_that("selected analysis based on the analysis plan would be executed", { - expect_snapshot(meta_run(meta, i = c(1, 3, 5))) + expect_null(meta_run(meta, i = c(1, 3, 5))[[1]]) }) diff --git a/tests/testthat/test-meta_validate.R b/tests/testthat/test-meta_validate.R index 96393c7..a4b351a 100644 --- a/tests/testthat/test-meta_validate.R +++ b/tests/testthat/test-meta_validate.R @@ -1,6 +1,5 @@ -meta <- meta_example() - test_that("Check data_type", { + meta <- meta_example() meta$data_population <- NULL expect_error(meta_validate(meta)) @@ -13,25 +12,32 @@ test_that("Check data_type", { expect_error(meta_validate(meta)) }) +test_that("Check group factor level", { + meta <- meta_example() + meta$data_population$TRTA <- factor(meta$data_population$TRTA, c("Placebo", "Xanomeline High Dose", "Xanomeline Low Dose")) + expect_error(meta_validate(meta)) +}) test_that("Check plan variable name", { + meta <- meta_example() names(meta$plan)[5] <- "param" expect_error(meta_validate(meta)) }) - - test_that("Check id variable", { + meta <- meta_example() meta$population$apat$id <- "id" expect_error(meta_validate(meta)) }) test_that("Check label variable", { + meta <- meta_example() meta$population$apat$label <- NULL expect_warning(meta_validate(meta)) }) test_that("Check observation variables in the datasets", { + meta <- meta_example() meta$observation$wk12$id <- "ID" expect_error(meta_validate(meta))