Skip to content

Commit

Permalink
Implement today() in model-methods.R
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Nov 14, 2024
1 parent 5b646c4 commit 04ca11b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ S3method(set_stats_names,epiworld_lfmcmc)
S3method(set_summary_fun,epiworld_lfmcmc)
S3method(size,epiworld_model)
S3method(summary,epiworld_model)
S3method(today,epiworld_model)
S3method(verbose_off,epiworld_model)
S3method(verbose_on,epiworld_model)
export(LFMCMC)
Expand Down Expand Up @@ -220,6 +221,7 @@ export(set_transmission_reduction)
export(set_transmission_reduction_fun)
export(set_transmission_reduction_ptr)
export(size)
export(today)
export(tool)
export(tool_fun_logit)
export(use_kernel_fun_gaussian)
Expand Down
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ get_ndays_cpp <- function(model) {
.Call(`_epiworldR_get_ndays_cpp`, model)
}

today_cpp <- function(model) {
.Call(`_epiworldR_today_cpp`, model)
}

get_n_replicates_cpp <- function(model) {
.Call(`_epiworldR_get_n_replicates_cpp`, model)
}
Expand Down
14 changes: 14 additions & 0 deletions R/model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ stopifnot_model <- function(model) {
#' get_ndays(model_sirconn) # Returns the length of the simulation in days. This
#' # will match "ndays" within the "run" function.
#'
#' today(model_sirconn) # Returns the current day of the simulation. This will
#' # match "get_ndays()" if run at the end of a simulation, but will differ if run
#' # during a simulation
#'
#' get_n_replicates(model_sirconn) # Returns the number of replicates of the
#' # model.
#'
Expand Down Expand Up @@ -275,6 +279,16 @@ get_ndays <- function(x) UseMethod("get_ndays")
get_ndays.epiworld_model <- function(x) get_ndays_cpp(x)


#' @export
#' @rdname epiworld-methods
#' @returns
#' - `today` returns the current model day
today <- function(x) UseMethod("today")

#' @export
today.epiworld_model <- function(x) today_cpp(x)


#' @export
#' @rdname epiworld-methods
#' @returns
Expand Down
11 changes: 11 additions & 0 deletions man/epiworld-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ extern "C" SEXP _epiworldR_get_ndays_cpp(SEXP model) {
END_CPP11
}
// model.cpp
int today_cpp(SEXP model);
extern "C" SEXP _epiworldR_today_cpp(SEXP model) {
BEGIN_CPP11
return cpp11::as_sexp(today_cpp(cpp11::as_cpp<cpp11::decay_t<SEXP>>(model)));
END_CPP11
}
// model.cpp
int get_n_replicates_cpp(SEXP model);
extern "C" SEXP _epiworldR_get_n_replicates_cpp(SEXP model) {
BEGIN_CPP11
Expand Down Expand Up @@ -1127,6 +1134,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_epiworldR_set_transmission_reduction_fun_cpp", (DL_FUNC) &_epiworldR_set_transmission_reduction_fun_cpp, 3},
{"_epiworldR_set_transmission_reduction_ptr_cpp", (DL_FUNC) &_epiworldR_set_transmission_reduction_ptr_cpp, 3},
{"_epiworldR_size_cpp", (DL_FUNC) &_epiworldR_size_cpp, 1},
{"_epiworldR_today_cpp", (DL_FUNC) &_epiworldR_today_cpp, 1},
{"_epiworldR_tool_cpp", (DL_FUNC) &_epiworldR_tool_cpp, 7},
{"_epiworldR_tool_fun_logit_cpp", (DL_FUNC) &_epiworldR_tool_fun_logit_cpp, 3},
{"_epiworldR_use_kernel_fun_gaussian_cpp", (DL_FUNC) &_epiworldR_use_kernel_fun_gaussian_cpp, 1},
Expand Down
8 changes: 8 additions & 0 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ int get_ndays_cpp(SEXP model) {

}

[[cpp11::register]]
int today_cpp(SEXP model) {

external_pointer<Model<>> ptr(model);
return static_cast<int>(ptr->today());

}

[[cpp11::register]]
int get_n_replicates_cpp(SEXP model) {

Expand Down

0 comments on commit 04ca11b

Please sign in to comment.