Skip to content

Commit ca06a82

Browse files
authored
Merge branch 'main' into 145-multi-ancova
2 parents 65266fe + 1fb059b commit ca06a82

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

R/impute.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,14 @@ validate_strategies <- function(strategies, reference) {
820820
for (ref in unique_references) {
821821
assert_that(
822822
ref %in% strat_names,
823-
msg = sprintf("Required strategy `%s` has not been defined", ref)
823+
msg = sprintf(
824+
"No implementation for strategy `%s` is available. Available strategies include:\n%s",
825+
ref,
826+
paste(sprintf(" - %s", strat_names), collapse = "\n")
827+
)
824828
)
825829
}
826-
return(invisible(TRUE))
830+
invisible(TRUE)
827831
}
828832

829833

tests/testthat/_snaps/impute.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# validate_strategies
2+
3+
Code
4+
cat(e$message)
5+
Output
6+
No implementation for strategy `NMAR` is available. Available strategies include:
7+
- A
8+
- MAR
9+
- AAA
10+

tests/testthat/test-impute.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,19 @@ test_that("validate_strategies", {
701701

702702
strats <- c("NMAR")
703703
expect_error(validate_strategies(strats, "NMAR"))
704+
705+
# #513 - Test that more informative error message is created when providing an invalid
706+
# strategy
707+
strats <- list(
708+
"A" = function(x) x,
709+
"MAR" = function(x) x,
710+
"AAA" = function(x) x
711+
)
712+
e <- tryCatch(
713+
validate_strategies(strats, "NMAR"),
714+
error = function(e) e
715+
)
716+
expect_snapshot(cat(e$message))
704717
})
705718

706719

0 commit comments

Comments
 (0)