From fd58ea6454347f9e702803317e6a54dd12320f0c Mon Sep 17 00:00:00 2001 From: Peter Winskill Date: Wed, 12 Jul 2023 14:27:26 +0100 Subject: [PATCH] Specify timesteps in create process --- DESCRIPTION | 2 +- R/model.R | 6 ++++-- R/processes.R | 2 ++ src/RcppExports.cpp | 2 +- tests/testthat/test-process-integration.R | 22 ++++++++++++++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3396705b..1d971723 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: malariasimulation Title: An individual based model for malaria -Version: 1.6.0 +Version: 1.6.1 Authors@R: c( person( given = "Giovanni", diff --git a/R/model.R b/R/model.R index 48af9af9..fb6ffef9 100644 --- a/R/model.R +++ b/R/model.R @@ -115,7 +115,8 @@ run_simulation <- function( solvers, correlations, list(create_lagged_eir(variables, solvers, parameters)), - list(create_lagged_infectivity(variables, parameters)) + list(create_lagged_infectivity(variables, parameters)), + timesteps ), variables = variables, events = unlist(events), @@ -206,6 +207,7 @@ run_metapop_simulation <- function( correlations[[i]], lagged_eir, lagged_infectivity, + timesteps, mixing[i,], i ) @@ -248,4 +250,4 @@ run_simulation_with_repetitions <- function( } ) do.call("rbind", dfs) -} \ No newline at end of file +} diff --git a/R/processes.R b/R/processes.R index 6109490f..d3b11fda 100644 --- a/R/processes.R +++ b/R/processes.R @@ -14,6 +14,7 @@ #' population and species in the simulation #' @param lagged_infectivity a list of LaggedValue objects for FOIM for each population #' in the simulation +#' @param timesteps Number of timesteps #' @param mixing a vector of mixing coefficients for the lagged transmission #' values (default: 1) #' @param mixing_index an index for this population's position in the @@ -29,6 +30,7 @@ create_processes <- function( correlations, lagged_eir, lagged_infectivity, + timesteps, mixing = 1, mixing_index = 1 ) { diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index f5c226fd..affb233d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -260,7 +260,7 @@ BEGIN_RCPP END_RCPP } -RcppExport SEXP run_testthat_tests(); +RcppExport SEXP run_testthat_tests(void); static const R_CallMethodDef CallEntries[] = { {"_malariasimulation_create_adult_mosquito_model", (DL_FUNC) &_malariasimulation_create_adult_mosquito_model, 5}, diff --git a/tests/testthat/test-process-integration.R b/tests/testthat/test-process-integration.R index f259be5e..1b07f127 100644 --- a/tests/testthat/test-process-integration.R +++ b/tests/testthat/test-process-integration.R @@ -19,6 +19,28 @@ test_that('create_processes makes valid process functions', { } }) +test_that('create_processes makes valid process functions when progress bar specified', { + parameters <- get_parameters() + parameters$progress_bar <- TRUE + events <- create_events(parameters) + variables <- create_variables(parameters) + vector_models <- parameterise_mosquito_models(parameters, 1) + solvers <- parameterise_solvers(vector_models, parameters) + renderer <- individual::Render$new(1) + processes <- create_processes( + renderer, + variables, + events, + parameters, + vector_models, + solvers, + timesteps = 100 + ) + for (process in processes) { + expect(is.function(process) || inherits(process, 'externalptr'), 'Process is not a function') + } +}) + test_that('attach_event_listeners makes valid listeners', { parameters <- get_parameters() events <- create_events(parameters)