Skip to content

Commit

Permalink
Merge pull request #426 from DeclareDesign/zero-row-sims-df
Browse files Browse the repository at this point in the history
add error when a simulations_df is sent with zero rows
  • Loading branch information
graemeblair committed Mar 22, 2020
2 parents 9104763 + bdf3c16 commit 94fdaeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/diagnose_design.R
Expand Up @@ -85,6 +85,9 @@ diagnose_design <- function(...,
if (is_empty(c("estimator_label", "estimand_label") %icn% simulations_df)) {
stop("Can't calculate diagnosands on this data.frame, which does not include either an estimator_label or an estimand_label. Did you send a simulations data frame?")
}
if (nrow(simulations_df) == 0) {
stop("Can't calculate diagnosands on this data.frame, which has zero rows.")
}
diagnosands <- diagnosands %||% attr(simulations_df, "diagnosands") %||% default_diagnosands
} else {
# simulate if needed ------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-diagnose-design.R
Expand Up @@ -299,3 +299,8 @@ test_that("diagnose_design works when simulations_df lacking parameters attr", {

expect_identical(d1,d2)
})


test_that("diagnose_design stops when a zero-row simulations_df is sent", {
expect_error(diagnose_design(data.frame(estimator_label = rep(1, 0))), "which has zero rows")
})

0 comments on commit 94fdaeb

Please sign in to comment.