Skip to content

Commit 4b112e5

Browse files
committed
refactor+tweak: add+use format_class_vec helper for messages
Collapse with empty string in order to not have extra whitespace if used with `cat` rather than `cli_*`.
1 parent 4290363 commit 4b112e5

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

R/archive.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ validate_version_bound <- function(version_bound, x, na_ok = FALSE,
4949
if (!identical(class(version_bound), class(x[["version"]]))) {
5050
cli_abort(
5151
"{version_bound_arg} must have the same `class` vector as x$version,
52-
which has a `class` of {paste(collapse = ' ', deparse(class(x$version)))}",
52+
which has a `class` of {format_class_vec(class(x$version))}",
5353
class = "epiprocess__version_bound_mismatched_class"
5454
)
5555
}

R/utils.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ paste_lines <- function(lines) {
8989
paste(paste0(lines, "\n"), collapse = "")
9090
}
9191

92+
#' Format a class vector as a string via deparsing it
93+
#'
94+
#' @param class_vec `chr`; output of `class(object)` for some `object`
95+
#' @return string
96+
format_class_vec <- function(class_vec) {
97+
paste(collapse = "", deparse(class_vec))
98+
}
99+
92100
#' Assert that a sliding computation function takes enough args
93101
#'
94102
#' @param f Function; specifies a computation to slide over an `epi_df` or
@@ -451,7 +459,7 @@ as_slide_computation <- function(f, ..., .ref_time_value_long_varnames, .ref_tim
451459
}
452460

453461
cli_abort(
454-
"Can't convert an object of class {paste(collapse = ' ', deparse(class(f)))}
462+
"Can't convert an object of class {format_class_vec(class(f))}
455463
to a slide computation",
456464
class = "epiprocess__as_slide_computation__cant_convert_catchall",
457465
epiprocess__f = f,

man/format_class_vec.Rd

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)