Skip to content

Commit

Permalink
Don't use cli_ with dynamic format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
brookslogan committed Apr 22, 2024
1 parent 6579fa7 commit 61daa60
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
14 changes: 4 additions & 10 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,21 +351,15 @@ new_epi_archive <- function(
validate_version_bound(versions_end, x, na_ok = FALSE)
if (nrow(x) > 0L && versions_end < max(x[["version"]])) {
cli_abort(
sprintf(
"`versions_end` was %s, but `x` contained
updates for a later version or versions, up through %s",
versions_end, max(x[["version"]])
),
"`versions_end` was {versions_end}, but `x` contained
updates for a later version or versions, up through {max(x$version)}",
class = "epiprocess__versions_end_earlier_than_updates"
)
}
if (!is.na(clobberable_versions_start) && clobberable_versions_start > versions_end) {
cli_abort(
sprintf(
"`versions_end` was %s, but a `clobberable_versions_start`
of %s indicated that there were later observed versions",
versions_end, clobberable_versions_start
),
"`versions_end` was {versions_end}, but a `clobberable_versions_start`
of {clobberable_versions_start} indicated that there were later observed versions",
class = "epiprocess__versions_end_earlier_than_clobberable_versions_start"
)
}
Expand Down
14 changes: 7 additions & 7 deletions R/methods-epi_archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ epix_fill_through_version <- function(x, fill_versions_end,
nonkey_cols <- setdiff(names(x$DT), key(x$DT))
next_version_tag <- next_after(x$versions_end)
if (next_version_tag > fill_versions_end) {
cli_abort(sprintf(paste(
"Apparent problem with `next_after` method:",
"archive contained observations through version %s",
"and the next possible version was supposed to be %s,",
"but this appeared to jump from a version < %3$s",
"to one > %3$s, implying at least one version in between."
), x$versions_end, next_version_tag, fill_versions_end))
cli_abort(paste(
"Apparent problem with {.code next_after} method:",
"archive contained observations through version {x$versions_end}",
"and the next possible version was supposed to be {next_version_tag},",
"but this appeared to jump from a version < {fill_versions_end}",
"to one > {fill_versions_end}, implying at least one version in between."
))
}
nonversion_key_vals_ever_recorded <- unique(x$DT, by = nonversion_key_cols)
# In edge cases, the `unique` result can alias the original
Expand Down
6 changes: 2 additions & 4 deletions R/methods-epi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ dplyr_reconstruct.epi_df <- function(data, template) {
dup_col_names <- cn[duplicated(cn)]
if (length(dup_col_names) != 0) {
cli_abort(paste0(
"Column name(s) ",
paste(unique(dup_col_names),
collapse = ", "
), " must not be duplicated."
"Column name(s) {unique(dup_col_names)}",
"must not be duplicated."
))
}

Expand Down
9 changes: 5 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ assert_sufficient_f_args <- function(f, ...) {
# `f` doesn't take enough args.
if (rlang::dots_n(...) == 0L) {
# common case; try for friendlier error message
cli_abort(sprintf("`f` must take at least %s arguments", n_mandatory_f_args),
cli_abort("`f` must take at least {n_mandatory_f_args} arguments",
class = "epiprocess__assert_sufficient_f_args__f_needs_min_args",
epiprocess__f = f
)
Expand Down Expand Up @@ -312,7 +312,7 @@ as_slide_computation <- function(f, ...) {

if (is_formula(f)) {
if (length(f) > 2) {
cli_abort(sprintf("%s must be a one-sided formula", arg),
cli_abort("{.code {arg}} must be a one-sided formula",
class = "epiprocess__as_slide_computation__formula_is_twosided",
epiprocess__f = f,
call = call
Expand Down Expand Up @@ -350,7 +350,8 @@ as_slide_computation <- function(f, ...) {
}

cli_abort(
sprintf("Can't convert an object of class %s to a slide computation", paste(collapse = " ", deparse(class(f)))),
"Can't convert an object of class {paste(collapse = ' ', deparse(class(f)))}
to a slide computation",
class = "epiprocess__as_slide_computation__cant_convert_catchall",
epiprocess__f = f,
epiprocess__f_class = class(f),
Expand Down Expand Up @@ -687,7 +688,7 @@ gcd_num <- function(dividends, ..., rrtol = 1e-6, pqlim = 1e6, irtol = 1e-6) {
guess_period <- function(ref_time_values, ref_time_values_arg = rlang::caller_arg(ref_time_values)) {
sorted_distinct_ref_time_values <- sort(unique(ref_time_values))
if (length(sorted_distinct_ref_time_values) < 2L) {
cli_abort(sprintf("Not enough distinct values in `%s` to guess the period.", ref_time_values_arg))
cli_abort("Not enough distinct values in {.code {ref_time_values_arg}} to guess the period.", ref_time_values_arg)
}
skips <- diff(sorted_distinct_ref_time_values)
decayed_skips <-
Expand Down

0 comments on commit 61daa60

Please sign in to comment.