diff --git a/NAMESPACE b/NAMESPACE index 60cd41c92..9e0f93970 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,14 @@ import(cmdstanr) import(ggplot2) importFrom(brms,bf) importFrom(brms,prior) +importFrom(checkmate,assert_data_frame) +importFrom(checkmate,assert_factor) +importFrom(checkmate,assert_integer) +importFrom(checkmate,assert_names) +importFrom(checkmate,assert_numeric) +importFrom(checkmate,assert_true) +importFrom(cli,cli_abort) +importFrom(cli,cli_inform) importFrom(dplyr,filter) importFrom(dplyr,mutate) importFrom(dplyr,select) diff --git a/R/defaults.R b/R/defaults.R index 5037777b5..5b866c408 100644 --- a/R/defaults.R +++ b/R/defaults.R @@ -5,7 +5,7 @@ #' @family defaults #' @export epidist_validate.default <- function(data, ...) { - cli::cli_abort( + cli_abort( "No epidist_validate method implemented for the class ", class(data), "\n", "See methods(epidist_validate) for available methods" ) @@ -18,7 +18,7 @@ epidist_validate.default <- function(data, ...) { #' @family defaults #' @export epidist_formula.default <- function(data, ...) { - cli::cli_abort( + cli_abort( "No epidist_formula method implemented for the class ", class(data), "\n", "See methods(epidist_formula) for available methods" ) @@ -31,7 +31,7 @@ epidist_formula.default <- function(data, ...) { #' @family defaults #' @export epidist_family.default <- function(data, ...) { - cli::cli_abort( + cli_abort( "No epidist_family method implemented for the class ", class(data), "\n", "See methods(epidist_family) for available methods" ) @@ -44,7 +44,7 @@ epidist_family.default <- function(data, ...) { #' @family defaults #' @export epidist_stancode.default <- function(data, ...) { - cli::cli_abort( + cli_abort( "No epidist_stancode method implemented for the class ", class(data), "\n", "See methods(epidist_stancode) for available methods" ) diff --git a/R/diagnostics.R b/R/diagnostics.R index 987a4a976..4a6bee9ef 100644 --- a/R/diagnostics.R +++ b/R/diagnostics.R @@ -22,12 +22,12 @@ #' @export epidist_diagnostics <- function(fit) { if (!inherits(fit, "epidist_fit")) { - cli::cli_abort(c( + cli_abort(c( "!" = "Diagnostics only supported for objects of class epidist_fit" )) } if (fit$algorithm %in% c("laplace", "meanfield", "fullrank", "pathfinder")) { - cli::cli_abort(c( + cli_abort(c( "!" = paste0( "Diagnostics not yet supported for the algorithm: ", fit$algorithm ) @@ -50,7 +50,7 @@ epidist_diagnostics <- function(fit) { per_at_max_treedepth = no_at_max_treedepth / samples ) } else { - cli::cli_abort(c( + cli_abort(c( "!" = paste0("Unrecognised algorithm: ", fit$algorithm) )) } diff --git a/R/epidist-package.R b/R/epidist-package.R index 4b493960e..279dc7394 100644 --- a/R/epidist-package.R +++ b/R/epidist-package.R @@ -7,5 +7,8 @@ ## usethis namespace: start #' @importFrom dplyr filter select #' @importFrom brms bf prior +#' @importFrom checkmate assert_data_frame assert_names assert_integer +#' assert_true assert_factor assert_numeric +#' @importFrom cli cli_abort cli_inform ## usethis namespace: end NULL diff --git a/R/latent_individual.R b/R/latent_individual.R index c69ae6609..5f3095893 100644 --- a/R/latent_individual.R +++ b/R/latent_individual.R @@ -8,20 +8,20 @@ as_latent_individual <- function(data) { } assert_latent_individual_input <- function(data) { - checkmate::assert_data_frame(data) - checkmate::assert_names( + assert_data_frame(data) + assert_names( names(data), must.include = c("case", "ptime_lwr", "ptime_upr", "stime_lwr", "stime_upr", "obs_at") ) - checkmate::assert_integer(data$case, lower = 0) - checkmate::assert_numeric(data$ptime_lwr, lower = 0) - checkmate::assert_numeric(data$ptime_upr, lower = 0) - checkmate::assert_true(all(data$ptime_upr - data$ptime_lwr > 0)) - checkmate::assert_numeric(data$stime_lwr, lower = 0) - checkmate::assert_numeric(data$stime_upr, lower = 0) - checkmate::assert_true(all(data$stime_upr - data$stime_lwr > 0)) - checkmate::assert_numeric(data$obs_at, lower = 0) + assert_integer(data$case, lower = 0) + assert_numeric(data$ptime_lwr, lower = 0) + assert_numeric(data$ptime_upr, lower = 0) + assert_true(all(data$ptime_upr - data$ptime_lwr > 0)) + assert_numeric(data$stime_lwr, lower = 0) + assert_numeric(data$stime_upr, lower = 0) + assert_true(all(data$stime_upr - data$stime_lwr > 0)) + assert_numeric(data$obs_at, lower = 0) } #' Prepare latent individual model @@ -76,9 +76,9 @@ as_latent_individual.data.frame <- function(data) { #' @family latent_individual #' @export epidist_validate.epidist_latent_individual <- function(data) { - checkmate::assert_true(is_latent_individual(data)) + assert_true(is_latent_individual(data)) assert_latent_individual_input(data) - checkmate::assert_names( + assert_names( names(data), must.include = c("case", "ptime_lwr", "ptime_upr", "stime_lwr", "stime_upr", "obs_at", @@ -86,13 +86,13 @@ epidist_validate.epidist_latent_individual <- function(data) { "swindow", "delay", "row_id") ) if (nrow(data) > 1) { - checkmate::assert_factor(data$row_id) + assert_factor(data$row_id) } - checkmate::assert_numeric(data$obs_t, lower = 0) - checkmate::assert_numeric(data$pwindow, lower = 0) - checkmate::assert_numeric(data$woverlap, lower = 0) - checkmate::assert_numeric(data$swindow, lower = 0) - checkmate::assert_numeric(data$delay, lower = 0) + assert_numeric(data$obs_t, lower = 0) + assert_numeric(data$pwindow, lower = 0) + assert_numeric(data$woverlap, lower = 0) + assert_numeric(data$swindow, lower = 0) + assert_numeric(data$delay, lower = 0) } #' Check if data has the `epidist_latent_individual` class diff --git a/R/postprocess.R b/R/postprocess.R index e8c506b5d..3742dbe6c 100644 --- a/R/postprocess.R +++ b/R/postprocess.R @@ -51,7 +51,7 @@ add_mean_sd <- function(data, ...) { #' @method add_mean_sd default #' @export add_mean_sd.default <- function(data, ...) { - cli::cli_inform(c( + cli_inform(c( "!" = "Natural scale mean and standard deviation parameter columns not added: no method available for this family", "Consider submitting an issue to https:/github.com/epinowcast/epidist" diff --git a/R/utils.R b/R/utils.R index 15f92b6ea..8b46dfc18 100644 --- a/R/utils.R +++ b/R/utils.R @@ -38,7 +38,7 @@ #' @param f A positive number specifying the multiple to be rounded down to #' @keywords internal .floor_mult <- function(x, f = 1) { - checkmate::assert_numeric(f, lower = 0) + assert_numeric(f, lower = 0) ifelse(f == 0, x, floor(x / f) * f) } @@ -75,7 +75,7 @@ "i" = "No available prior to replace in old_prior found for:", missing_prior ) - cli::cli_abort(message = msg) + cli_abort(message = msg) } prior <- prior |>