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

Add error message when plotting a model that hasn't been run #56

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/plot_epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ plot_epi.epiworld_model <- function(
counts_scale,
...
) {
# Check if model has been run
if (length(get_hist_total(x)$counts) <= 0)
stop("The model must be run before it can be plotted.")

plot_epi(
x = get_hist_total(x),
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-seir.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ expect_silent(agents_smallworld(
expect_silent(verbose_off(seir_0))
expect_silent(queuing_off(seir_0))
expect_silent(initial_states(seir_0, c(.3, .5)))
expect_warning(expect_error(plot(seir_0))) # Plot fails before model is run
expect_error(plot(seir_0), "model must be run before it can be plotted")
expect_silent(run(seir_0, ndays = 100, seed = 1231))
expect_silent(plot(seir_0)) # Plot succeeds after model is run

Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-sir.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ expect_silent(agents_smallworld(

# Check model run with queuing -------------------------------------------------
expect_silent(verbose_off(sir_0))
expect_warning(expect_error(plot(sir_0))) # Plot fails before model is run
expect_error(plot(sir_0), "model must be run before it can be plotted")
expect_silent(run(sir_0, ndays = 50, seed = 1912))
expect_silent(plot(sir_0)) # Plot succeeds after model is run

Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-sirconn.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ expect_length(class(sirconn_0), 2)
# Check model run with queuing -------------------------------------------------
expect_silent(verbose_off(sirconn_0))
expect_warning(queuing_on(sirconn_0))
expect_warning(expect_error(plot(sirconn_0))) # Plot fails before model is run
expect_error(plot(sirconn_0), "model must be run before it can be plotted")
expect_silent(run(sirconn_0, ndays = 100, seed = 131))
expect_silent(plot(sirconn_0)) # Plot succeeds after model is run

Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-sird.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ expect_silent(agents_smallworld(
# Check model run --------------------------------------------------------------
expect_silent(verbose_off(sird_0))
expect_silent(initial_states(sird_0, c(.05, .05)))
expect_warning(expect_error(plot(sird_0))) # Plot fails before model is run
expect_error(plot(sird_0), "model must be run before it can be plotted")
expect_silent(run(sird_0, ndays = 100, seed = 1231))
expect_silent(plot(sird_0)) # Plot succeeds after model is run

Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-sis.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ expect_silent(agents_smallworld(

# Check model run --------------------------------------------------------------
expect_silent(verbose_off(sis_0))
expect_warning(expect_error(plot(sis_0))) # Plot fails before model is run
expect_error(plot(sis_0), "model must be run before it can be plotted")
expect_silent(run_multiple(
sis_0,
ndays=100,
Expand Down
Loading