Skip to content

Commit

Permalink
Issue #341: Add cli and checkmate functions to namespace (#344)
Browse files Browse the repository at this point in the history
* Put checkmate functions into NAMESPACE

* Put cli functions into NAMESPACE

* Add assert_numeric
  • Loading branch information
athowes authored Sep 19, 2024
1 parent 21784f4 commit bc10a37
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions R/defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand Down
6 changes: 3 additions & 3 deletions R/diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
))
}
Expand Down
3 changes: 3 additions & 0 deletions R/epidist-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 18 additions & 18 deletions R/latent_individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,23 +76,23 @@ 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",
"obs_t", "pwindow", "woverlap",
"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
Expand Down
2 changes: 1 addition & 1 deletion R/postprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 |>
Expand Down

0 comments on commit bc10a37

Please sign in to comment.