diff --git a/R/plot_epi.R b/R/plot_epi.R index b263a93..5ecc1ed 100644 --- a/R/plot_epi.R +++ b/R/plot_epi.R @@ -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), diff --git a/inst/tinytest/test-seir.R b/inst/tinytest/test-seir.R index a41591a..1224f41 100644 --- a/inst/tinytest/test-seir.R +++ b/inst/tinytest/test-seir.R @@ -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 diff --git a/inst/tinytest/test-sir.R b/inst/tinytest/test-sir.R index c9bcd46..fbfd375 100644 --- a/inst/tinytest/test-sir.R +++ b/inst/tinytest/test-sir.R @@ -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 diff --git a/inst/tinytest/test-sirconn.R b/inst/tinytest/test-sirconn.R index 2a88274..48fdf47 100644 --- a/inst/tinytest/test-sirconn.R +++ b/inst/tinytest/test-sirconn.R @@ -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), "SIR Connected models do not have queue.") -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 diff --git a/inst/tinytest/test-sird.R b/inst/tinytest/test-sird.R index 4e20166..231d927 100644 --- a/inst/tinytest/test-sird.R +++ b/inst/tinytest/test-sird.R @@ -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 diff --git a/inst/tinytest/test-sis.R b/inst/tinytest/test-sis.R index b4c3b62..37dfda2 100644 --- a/inst/tinytest/test-sis.R +++ b/inst/tinytest/test-sis.R @@ -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,