Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions R/arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
if (length(common_args) > 0) {
args <- args[!(names(args) %in% common_args)]
common_args <- paste0(common_args, collapse = ", ")
rlang::warn(
glue::glue(
"The following arguments cannot be manually modified ",
"and were removed: {common_args}."
)
cli::cli_warn(
"The arguments {common_args} cannot be manually modified and were removed."

Check warning on line 12 in R/arguments.R

View check run for this annotation

Codecov / codecov/patch

R/arguments.R#L11-L12

Added lines #L11 - L12 were not covered by tests
)
}
args
Expand All @@ -32,7 +29,7 @@
none = rlang::expr(x),
data.frame = rlang::expr(maybe_data_frame(x)),
matrix = rlang::expr(maybe_matrix(x)),
rlang::abort(glue::glue("Invalid data type target: {target}."))
cli::cli_abort("Invalid data type target: {target}.")
)

fit_call <- make_call(
Expand Down Expand Up @@ -78,7 +75,7 @@
set_args.cluster_spec <- function(object, ...) {
the_dots <- enquos(...)
if (length(the_dots) == 0) {
rlang::abort("Please pass at least one named argument.")
cli::cli_abort("Please pass at least one named argument.")
}
main_args <- names(object$args)
new_args <- names(the_dots)
Expand Down
2 changes: 1 addition & 1 deletion R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ augment.cluster_fit <- function(x, new_data, ...) {
stats::predict(x, new_data = new_data)
)
} else {
rlang::abort(paste("Unknown mode:", x$spec$mode))
cli::cli_abort("Unknown mode: {x$spec$mode}")
}
as_tibble(ret)
}
4 changes: 2 additions & 2 deletions R/control.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ check_control <- function(x, call = rlang::caller_env()) {
abs(x - round(x)) < tol
}
if (!int_check(x$verbosity)) {
rlang::abort("verbosity should be an integer.", call = call)
cli::cli_abort("verbosity should be an integer.", call = call)
}
if (!is.logical(x$catch)) {
rlang::abort("catch should be a logical.", call = call)
cli::cli_abort("catch should be a logical.", call = call)
}
x
}
Expand Down
30 changes: 15 additions & 15 deletions R/convert_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
remove_intercept = TRUE
) {
if (!(composition %in% c("data.frame", "matrix"))) {
rlang::abort("`composition` should be either 'data.frame' or 'matrix'.")
cli::cli_abort(
"{.arg composition} should be {.cls data.frame} or {.cls matrix}."
)

Check warning on line 47 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L45-L47

Added lines #L45 - L47 were not covered by tests
}

## Assemble model.frame call from call arguments
Expand All @@ -59,7 +61,7 @@

w <- as.vector(model.weights(mod_frame))
if (!is.null(w) && !is.numeric(w)) {
rlang::abort("`weights` must be a numeric vector")
cli::cli_abort("The {.arg weights} must be a numeric vector.")

Check warning on line 64 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L64

Added line #L64 was not covered by tests
}

# TODO: Do we actually use the offset when fitting?
Expand Down Expand Up @@ -124,15 +126,11 @@
good_args <- c("subset", "weights")
good_names <- names(x) %in% good_args
if (any(!good_names)) {
rlang::abort(
glue::glue(
"These argument(s) cannot be used to create the data: ",
glue::glue_collapse(
glue::glue("`{names(x)[!good_names]}`"),
sep = ", "
),
". Possible arguments are: ",
glue::glue_collapse(glue::glue("`{good_args}`"), sep = ", ")
cli::cli_abort(
c(
"The argument{?s} {.code {names(x)[!good_names]}} cannot be used
to create the data.",
"i" = "Possible arguments are: {.code {good_args}}."

Check warning on line 133 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L129-L133

Added lines #L129 - L133 were not covered by tests
)
)
}
Expand All @@ -159,7 +157,7 @@
#' @keywords internal
.convert_x_to_form_fit <- function(x, weights = NULL, remove_intercept = TRUE) {
if (is.vector(x)) {
rlang::abort("`x` cannot be a vector.")
cli::cli_abort("{.arg x} cannot be a vector.")

Check warning on line 160 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L160

Added line #L160 was not covered by tests
}

if (remove_intercept) {
Expand All @@ -182,10 +180,10 @@

if (!is.null(weights)) {
if (!is.numeric(weights)) {
rlang::abort("`weights` must be a numeric vector")
cli::cli_abort("The {.arg weights} must be a numeric vector.")

Check warning on line 183 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L183

Added line #L183 was not covered by tests
}
if (length(weights) != nrow(x)) {
rlang::abort(glue::glue("`weights` should have {nrow(x)} elements"))
cli::cli_abort("{.arg weights} should have {nrow(x)} elements.")

Check warning on line 186 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L186

Added line #L186 was not covered by tests
}
}

Expand Down Expand Up @@ -219,7 +217,9 @@
composition = "data.frame"
) {
if (!(composition %in% c("data.frame", "matrix"))) {
rlang::abort("`composition` should be either 'data.frame' or 'matrix'.")
cli::cli_abort(
"{.arg composition} should be either {.code data.frame} or {.code matrix}."
)

Check warning on line 222 in R/convert_data.R

View check run for this annotation

Codecov / codecov/patch

R/convert_data.R#L220-L222

Added lines #L220 - L222 were not covered by tests
}

mod_terms <- object$terms
Expand Down
19 changes: 10 additions & 9 deletions R/engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
.groups = "drop"
)
if (nrow(info) == 0) {
rlang::abort(glue::glue("No known engines for `{cls}()`."), call = call)
cli::cli_abort("No known engines for {.fn {cls}}.", call = call)

Check warning on line 45 in R/engines.R

View check run for this annotation

Codecov / codecov/patch

R/engines.R#L45

Added line #L45 was not covered by tests
}
msg <- paste0(info$msg, collapse = ", ")
msg <- paste("Missing engine. Possible mode/engine combinations are:", msg)
rlang::abort(msg, call = call)
cli::cli_abort(
c(
"Missing engine.",
"i" = "Possible mode/engine combinations are: {info$msg}."
),
call = call
)
}

load_libs <- function(x, quiet, attach = FALSE) {
Expand Down Expand Up @@ -86,11 +90,8 @@
if (any(!is_inst)) {
missing_pkg <- x$method$libs[!is_inst]
missing_pkg <- paste0(missing_pkg, collapse = ", ")
rlang::abort(
glue::glue(
"This engine requires some package installs: ",
glue::glue_collapse(glue::glue("'{missing_pkg}'"), sep = ", ")
),
cli::cli_abort(
"This engine requires installing {.pkg {missing_pkg}}.",

Check warning on line 94 in R/engines.R

View check run for this annotation

Codecov / codecov/patch

R/engines.R#L93-L94

Added lines #L93 - L94 were not covered by tests
call = call
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
if (any(names(x) == "fit")) {
return(x$fit)
}
rlang::abort("Internal error: The model fit does not have an engine fit.")
cli::cli_abort("Internal error: The model fit does not have an engine fit.")

Check warning on line 55 in R/extract.R

View check run for this annotation

Codecov / codecov/patch

R/extract.R#L55

Added line #L55 was not covered by tests
}
26 changes: 13 additions & 13 deletions R/extract_cluster_assignment.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ extract_cluster_assignment <- function(object, ...) {

#' @export
extract_cluster_assignment.cluster_spec <- function(object, ...) {
rlang::abort(
paste(
cli::cli_abort(
c(
"This function requires a fitted model.",
"Please use `fit()` on your cluster specification."
"i" = "Please use {.fn fit} on your cluster specification."
)
)
}
Expand Down Expand Up @@ -121,20 +121,20 @@ extract_cluster_assignment.hclust <- function(
args <- list(...)

if (!is.null(args[["h"]])) {
rlang::abort(
paste(
"Using `h` argument is not supported.",
"Please use `cut_height` instead."
cli::cli_abort(
c(
"Using {.arg h} argument is not supported.",
"i" = "Please use {.arg cut_height} instead."
),
call = call
)
}

if (!is.null(args[["k"]])) {
rlang::abort(
paste(
"Using `k` argument is not supported.",
"Please use `num_clusters` instead."
cli::cli_abort(
c(
"Using {.arg k} argument is not supported.",
"i" = "Please use {.arg num_clusters} instead."
),
call = call
)
Expand All @@ -149,8 +149,8 @@ extract_cluster_assignment.hclust <- function(
}

if (is.null(num_clusters) && is.null(cut_height)) {
rlang::abort(
"Please specify either `num_clusters` or `cut_height`.",
cli::cli_abort(
"Please specify either {.arg num_clusters} or {.arg cut_height}.",
call = call
)
}
Expand Down
6 changes: 3 additions & 3 deletions R/extract_fit_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ extract_fit_summary.cluster_spec <- function(
...,
call = rlang::caller_env(n = 0)
) {
rlang::abort(
paste(
cli::cli_abort(
c(
"This function requires a fitted model.",
"Please use `fit()` on your cluster specification."
"i" = "Please use {.fn fit} on your cluster specification."
),
call = call
)
Expand Down
6 changes: 1 addition & 5 deletions R/extract_parameter_set_dials.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@
silent = TRUE
)
if (inherits(res, "try-error")) {
rlang::abort(
glue::glue(
"Error when calling {x$fun}(): {as.character(res)}"
)
)
cli::cli_abort("Error when calling {.fn {x$fun}}: {as.character(res)}")

Check warning on line 39 in R/extract_parameter_set_dials.R

View check run for this annotation

Codecov / codecov/patch

R/extract_parameter_set_dials.R#L39

Added line #L39 was not covered by tests
}
} else {
res <- NA
Expand Down
4 changes: 2 additions & 2 deletions R/finalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @export
finalize_model_tidyclust <- function(x, parameters) {
if (!inherits(x, "cluster_spec")) {
rlang::abort("`x` should be a tidyclust model specification.")
cli::cli_abort("{.arg x} should be a tidyclust model specification.")

Check warning on line 25 in R/finalize.R

View check run for this annotation

Codecov / codecov/patch

R/finalize.R#L25

Added line #L25 was not covered by tests
}
parsnip::check_final_param(parameters)
pset <- hardhat::extract_parameter_set_dials(x)
Expand All @@ -46,7 +46,7 @@
#' @export
finalize_workflow_tidyclust <- function(x, parameters) {
if (!inherits(x, "workflow")) {
rlang::abort("`x` should be a workflow")
cli::cli_abort("{.arg x} should be {.obj_type_friendly workflow}")

Check warning on line 49 in R/finalize.R

View check run for this annotation

Codecov / codecov/patch

R/finalize.R#L49

Added line #L49 was not covered by tests
}
parsnip::check_final_param(parameters)

Expand Down
34 changes: 14 additions & 20 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
...
) {
if (object$mode == "unknown") {
rlang::abort("Please set the mode in the model specification.")
cli::cli_abort("Please set the mode in the model specification.")

Check warning on line 96 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L96

Added line #L96 was not covered by tests
}

control <- parsnip::condense_control(control, control_cluster())
Expand All @@ -103,13 +103,14 @@
eng_vals <- possible_engines(object)
object$engine <- eng_vals[1]
if (control$verbosity > 0) {
rlang::warn(glue::glue("Engine set to `{object$engine}`."))
cli::cli_warn("Engine set to {.code {object$engine}}.")

Check warning on line 106 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L106

Added line #L106 was not covered by tests
}
}

if (all(c("x", "y") %in% names(dots))) {
rlang::abort(
"`fit.cluster_spec()` is for the formula methods. Use `fit_xy()` instead."
cli::cli_abort(
"The {.fn fit.cluster_spec} function is for the formula methods.
Use {.fn fit_xy} instead."

Check warning on line 113 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L111-L113

Added lines #L111 - L113 were not covered by tests
)
}
cl <- match.call(expand.dots = TRUE)
Expand Down Expand Up @@ -159,7 +160,7 @@
target = object$method$fit$interface,
...
),
rlang::abort(glue::glue("{interfaces} is unknown."))
cli::cli_abort("{interfaces} is unknown.")
)
model_classes <- class(res$fit)
class(res) <- c(paste0("_", model_classes[1]), "cluster_fit")
Expand All @@ -176,24 +177,17 @@
if (form_interface) {
return("formula")
}
rlang::abort("Error when checking the interface.")
cli::cli_abort("Error when checking the interface.")

Check warning on line 180 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L180

Added line #L180 was not covered by tests
}

inher <- function(x, cls, cl) {
if (!is.null(x) && !inherits(x, cls)) {
call <- match.call()
obj <- deparse(call[["x"]])
if (length(cls) > 1) {
rlang::abort(
glue::glue(
"`{obj}` should be one of the following classes: ",
glue::glue_collapse(glue::glue("'{cls}'"), sep = ", ")
)
)
cli::cli_abort("{.code {obj}} should be {.cls {cls}}.")

Check warning on line 188 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L188

Added line #L188 was not covered by tests
} else {
rlang::abort(
glue::glue("`{obj}` should be a {cls} object")
)
cli::cli_abort("{.code {obj}} should be {.obj_type_friendly {cls}}.")

Check warning on line 190 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L190

Added line #L190 was not covered by tests
}
}
invisible(x)
Expand Down Expand Up @@ -241,14 +235,14 @@
control <- parsnip::condense_control(control, control_cluster())

if (is.null(colnames(x))) {
rlang::abort("'x' should have column names.")
cli::cli_abort("{.arg x} should have column names.")

Check warning on line 238 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L238

Added line #L238 was not covered by tests
}

if (is.null(object$engine)) {
eng_vals <- possible_engines(object)
object$engine <- eng_vals[1]
if (control$verbosity > 0) {
rlang::warn(glue::glue("Engine set to `{object$engine}`."))
cli::cli_warn("Engine set to {.code {object$engine}}.")

Check warning on line 245 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L245

Added line #L245 was not covered by tests
}
}

Expand Down Expand Up @@ -298,7 +292,7 @@
control = control,
...
),
rlang::abort(glue::glue("{interfaces} is unknown."))
cli::cli_abort("{interfaces} is unknown.")
)
model_classes <- class(res$fit)
class(res) <- c(paste0("_", model_classes[1]), "cluster_fit")
Expand All @@ -309,7 +303,7 @@
sparse_ok <- allow_sparse(model)
sparse_x <- inherits(x, "dgCMatrix")
if (!sparse_ok && sparse_x) {
rlang::abort(
cli::cli_abort(

Check warning on line 306 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L306

Added line #L306 was not covered by tests
"Sparse matrices not supported by this model/engine combination."
)
}
Expand All @@ -334,7 +328,7 @@
if (df_interface) {
return("data.frame")
}
rlang::abort("Error when checking the interface")
cli::cli_abort("Error when checking the interface")

Check warning on line 331 in R/fit.R

View check run for this annotation

Codecov / codecov/patch

R/fit.R#L331

Added line #L331 was not covered by tests
}

allow_sparse <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion R/fit_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ form_x <- function(object, control, env, target = "none", ...) {

x_x <- function(object, env, control, target = "none", y = NULL, ...) {
if (!is.null(y) && length(y) > 0) {
rlang::abort("Outcomes are not used in `cluster_spec` objects.")
cli::cli_abort("Outcomes are not used in {.cls cluster_spec} objects.")
}
encoding_info <-
modelenv::get_encoding(class(object)[1]) %>%
Expand Down
2 changes: 1 addition & 1 deletion R/hier_clust.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
args <- lapply(object$args, rlang::eval_tidy)

if (all(is.numeric(args$num_clusters)) && any(args$num_clusters < 0)) {
rlang::abort("The number of centers should be >= 0.")
cli::cli_abort("The number of centers should be >= 0.")

Check warning on line 159 in R/hier_clust.R

View check run for this annotation

Codecov / codecov/patch

R/hier_clust.R#L159

Added line #L159 was not covered by tests
}

invisible(object)
Expand Down
Loading
Loading