diff --git a/DESCRIPTION b/DESCRIPTION index 48470ee02..ad3fd9063 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -543,6 +543,7 @@ Depends: R (>= 3.5) Imports: backports, + cli, dplyr (>= 1.0.0), generics (>= 0.0.2), glue, diff --git a/NAMESPACE b/NAMESPACE index eaca26a90..b7050c7b2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -299,6 +299,7 @@ export(glance) export(tidy) export(tidy_irlba) import(dplyr) +import(rlang) importFrom(generics,augment) importFrom(generics,glance) importFrom(generics,tidy) diff --git a/R/aaa-documentation-helper.R b/R/aaa-documentation-helper.R index 9eae8fc31..84dd92a69 100644 --- a/R/aaa-documentation-helper.R +++ b/R/aaa-documentation-helper.R @@ -26,11 +26,10 @@ return_evalrd <- function(..., .method, .pre = NULL, .post = NULL) { not_found <- setdiff(pull_from_modeltests, glos_env$column_glossary$column) if (length(not_found) > 0) { - not_found <- paste(not_found, collapse = ", ") - stop( - glue( - "Tried to use modeltests documentation for: {not_found} column(s) ", - "but could not find any." + cli::cli_abort( + c( + "Tried to use modeltests documentation for: {not_found} column{?s}.", + "i" = "No documentation could be found." ) ) } @@ -67,11 +66,10 @@ return_evalrd <- function(..., .method, .pre = NULL, .post = NULL) { written <- purrr::map_lgl(cols_exps, stringr::str_detect, string = result) missing_cols <- standard_cols[!written] if (length(missing_cols) != 0) { - cols_message <- glue( - 'The return_{.method} input "{missing_cols}" did not ', - "result in any documentation being written. \n" + cli::cli_inform( + "The {.code return_{.method}} input {.val {missing_cols}} did not + result in any documentation being written." ) - message(cols_message) } result diff --git a/R/broom-package.R b/R/broom-package.R index 9c797ea27..edd798ec5 100644 --- a/R/broom-package.R +++ b/R/broom-package.R @@ -20,6 +20,8 @@ #' @importFrom purrr map_df set_names possibly #' @importFrom tibble tibble as_tibble #' @importFrom tidyr pivot_longer pivot_wider +#' +#' @import rlang #' #' @importFrom utils head #' @importFrom glue glue diff --git a/R/data-frame.R b/R/data-frame.R index 3b01eea95..4bc7da480 100644 --- a/R/data-frame.R +++ b/R/data-frame.R @@ -1,17 +1,15 @@ #' @export glance.data.frame <- function(x, ...) { - stop( - "There is no glance method for data frames. ", - "Did you mean `tibble::glimpse()`?", - call. = FALSE - ) + cli::cli_abort(c( + "There is no {.fn glance} method for data frames.", + "i" = "Did you mean {.fn tibble::glimpse}?" + )) } #' @export glance.tbl_df <- function(x, ...) { - stop( - "There is no glance method for tibbles. ", - "Did you mean `tibble::glimpse()`?", - call. = FALSE - ) + cli::cli_abort(c( + "There is no glance method for tibbles.", + "i" = "Did you mean {.fn tibble::glimpse}?" + )) } diff --git a/R/deprecated-0-7-0.R b/R/deprecated-0-7-0.R index c89226ac7..cdb4d23cb 100644 --- a/R/deprecated-0-7-0.R +++ b/R/deprecated-0-7-0.R @@ -154,7 +154,9 @@ tidy.data.frame <- function(x, ..., na.rm = TRUE, trim = 0.1) { #' @export #' @family deprecated augment.data.frame <- function(x, data, ...) { - stop(paste("augment's first argument should be a model, not a data.frame")) + cli::cli_abort( + "{.arg x} should be a model, not a {.cls data.frame}." + ) } @@ -275,7 +277,10 @@ fix_data_frame <- function(x, newnames = NULL, newcol = "term") { ) if (!is.null(newnames) && length(newnames) != ncol(x)) { - stop("newnames must be NULL or have length equal to number of columns") + cli::cli_abort( + "{.arg newnames} must be {.code NULL} or have length + equal to the number of columns." + ) } if (all(rownames(x) == seq_len(nrow(x)))) { diff --git a/R/drc.R b/R/drc.R index bdc25b3f4..9dac0be90 100644 --- a/R/drc.R +++ b/R/drc.R @@ -102,7 +102,7 @@ glance.drc <- function(x, ...) { augment.drc <- function(x, data = NULL, newdata = NULL, se_fit = FALSE, conf.int = FALSE, conf.level = 0.95, ...) { if (is.null(data) && is.null(newdata)) { - stop("Must specify either `data` or `newdata` argument.", call. = FALSE) + cli::cli_abort("Must specify either {.arg data} or {.arg newdata} argument.") } # drc doesn't like tibbles diff --git a/R/ergm.R b/R/ergm.R index b598b466c..57915c52d 100644 --- a/R/ergm.R +++ b/R/ergm.R @@ -82,7 +82,10 @@ tidy.ergm <- function(x, conf.int = FALSE, conf.level = 0.95, if (exponentiate) { if (is.null(x$glm) || (x$glm$family$link != "logit" && x$glm$family$link != "log")) { - warning("Exponentiating but model didn't use log or logit link.") + cli::cli_warn( + "Coefficients will be exponentiated, but the model didn't + use a {.code log} or {.code logit} link." + ) } ret <- exponentiate(ret) @@ -152,9 +155,12 @@ glance.ergm <- function(x, deviance = FALSE, mcmc = FALSE, ...) { if (mcmc) { if (isTRUE(x$MPLE_is_MLE)) { - message( - "Though `glance` was supplied `mcmc = TRUE`, the model was not fitted", - "using MCMC, so the corresponding columns will be omitted." + cli::cli_inform( + c( + "Though {.fn glance} was supplied {.code mcmc = TRUE}, the model was not + fitted using MCMC,", + "i" = "The corresponding columns will be omitted." + ) ) } diff --git a/R/fixest.R b/R/fixest.R index 78bbebf84..45f8da7c2 100644 --- a/R/fixest.R +++ b/R/fixest.R @@ -104,11 +104,11 @@ augment.fixest <- function( type.residuals = c("response", "deviance", "pearson", "working"), ...) { if (!x$method %in% c("feols", "feglm", "femlm")) { - stop( - "augment is only supported for fixest models estimated with ", - "feols, feglm, or femlm\n", - " (supplied model used ", x$method, ")" - ) + cli::cli_abort(c( + "augment is only supported for fixest models estimated with + {.fn feols}, {.fn feglm}, or {.fn femlm}.", + "i" = "Supplied model used {.fn {x$method}}." + )) } type.predict <- match.arg(type.predict) type.residuals <- match.arg(type.residuals) @@ -119,7 +119,9 @@ augment.fixest <- function( df <- newdata } if (is.null(df)) { - stop("Must specify either `data` or `newdata` argument.", call. = FALSE) + cli::cli_abort( + "Must specify either a {.arg data} or {.arg newdata} argument." + ) } df <- as_augment_tibble(df) if (is.null(newdata)) { diff --git a/R/geepack.R b/R/geepack.R index ce3edc36a..03e9a7f49 100644 --- a/R/geepack.R +++ b/R/geepack.R @@ -58,10 +58,10 @@ tidy.geeglm <- function(x, conf.int = FALSE, conf.level = .95, if (exponentiate) { if (is.null(x$family) || (x$family$link != "logit" && x$family$link != "log")) { - warning(paste( - "Exponentiating coefficients, but model did not use", - "a log or logit link function" - )) + cli::cli_warn( + "Coefficients will be exponentiated, but the model didn't + use a {.code log} or {.code logit} link." + ) } ret <- exponentiate(ret) diff --git a/R/joinerml.R b/R/joinerml.R index 9f4c1076c..5f2ca8422 100644 --- a/R/joinerml.R +++ b/R/joinerml.R @@ -79,7 +79,7 @@ tidy.mjoint <- function(x, component = "survival", conf.int = FALSE, component <- rlang::arg_match(component, c("survival", "longitudinal")) if (!is.null(boot_se)) { if (!inherits(x = boot_se, "bootSE")) { - stop("`boot_se` argument must be a `bootSE` object.", call. = FALSE) + cli::cli_abort("{.arg boot_se} must be a {.cls bootSE} object.") } } @@ -141,17 +141,21 @@ augment.mjoint <- function(x, data = x$data, ...) { check_ellipses("newdata", "augment", "mjoint", ...) if (is.null(data)) { - stop( - "`data` argument is NULL. Try specifying `data` manually.", - call. = FALSE + cli::cli_abort( + c( + "{.arg data} argument is {.code NULL}.", + "i" = "Try specifying {.arg data} manually." + ) ) } if (length(data) > 1) { if (!do.call(all.equal, data)) { - stop( - "List of 'data' extracted from 'x' does not", - "include equal data frames." + cli::cli_abort( + c( + "List of {.arg data} extracted from {.arg x} does not include equal + data frames." + ) ) } data <- data[[1]] diff --git a/R/lfe.R b/R/lfe.R index ec5fa372d..95b11ce94 100644 --- a/R/lfe.R +++ b/R/lfe.R @@ -66,7 +66,11 @@ tidy.felm <- function(x, conf.int = FALSE, conf.level = .95, fe = FALSE, se.type # warn users about deprecated "robust" argument dots <- list(...) if (!is.null(dots$robust)) { - warning('\nThe "robust" argument has been deprecated in tidy.felm and will be ignored. Please use the "se.type" argument instead.\n') + cli::cli_warn(c( + "The {.arg robust} argument has been deprecated in {.fn tidy.felm} and + will be ignored.", + "i" = "Please use the {.arg se.type} argument instead." + )) } # match SE args @@ -83,7 +87,10 @@ tidy.felm <- function(x, conf.int = FALSE, conf.level = .95, fe = FALSE, se.type } else { # catch potential user error, asking for clusters where none exist if (se.type == "cluster" && is.null(x$clustervar)) { - warning("Clustered SEs requested, but weren't calculated in underlying model object. Reverting to default SEs.\n") + cli::cli_warn(c( + "Clustered SEs requested, but weren't calculated in underlying model object.", + "i" = "Reverting to default SEs." + )) se.type <- NULL } @@ -203,10 +210,7 @@ augment.felm <- function(x, data = model.frame(x), ...) { has_multi_response <- length(x$lhs) > 1 if (has_multi_response) { - stop( - "Augment does not support linear models with multiple responses.", - call. = FALSE - ) + cli::cli_abort("{.fn felm} models with multiple responses are not supported.") } df <- as_augment_tibble(data) mutate(df, .fitted = as.vector(x$fitted.values), .resid = as.vector(x$residuals)) @@ -233,12 +237,9 @@ glance.felm <- function(x, ...) { has_multi_response <- length(x$lhs) > 1 if (has_multi_response) { - stop( - "Glance does not support linear models with multiple responses.", - call. = FALSE - ) + cli::cli_abort("{.fn felm} models with multiple responses are not supported.") } - + s <- summary(x) as_glance_tibble( diff --git a/R/list-svd.R b/R/list-svd.R index 792a36d72..943712df7 100644 --- a/R/list-svd.R +++ b/R/list-svd.R @@ -40,7 +40,7 @@ #' @family list tidiers tidy_svd <- function(x, matrix = "u", ...) { if (length(matrix) > 1) { - stop("Must specify a single matrix to tidy.") + cli::cli_abort("Must specify a single matrix to tidy.") } if (matrix == "u") { diff --git a/R/list-xyz.R b/R/list-xyz.R index 253a87297..61c6626c8 100644 --- a/R/list-xyz.R +++ b/R/list-xyz.R @@ -25,16 +25,15 @@ #' tidy_xyz <- function(x, ...) { if (!is.matrix(x$z)) { - stop("To tidy an xyz list, `z` must be a matrix.", call. = FALSE) + cli::cli_abort("{.arg z} must be a matrix.") } if (length(x$x) != nrow(x$z) || length(x$y) != ncol(x$z)) { - stop( - "To tidy an xyz list, the length of element `x` must equal the number ", - "the number of rows of element `z`, and the length of element `y` must ", - "equal the number of columns of element `z`.", - call. = FALSE - ) + cli::cli_abort(c( + "To tidy an xyz list, the length of element {.code x} must equal the + number of rows of element {.code z}, and the length of element + {.code y} must equal the number of columns of element {.code z}." + )) } as_tibble(data.frame( diff --git a/R/list.R b/R/list.R index 16987e966..d46412c5c 100644 --- a/R/list.R +++ b/R/list.R @@ -33,7 +33,7 @@ tidy.list <- function(x, ...) { } else if (all(svd_elems %in% names(x))) { tidy_svd(x, ...) } else { - stop("No tidy method recognized for this list.", call. = FALSE) + cli::cli_abort("No {.fn tidy} method recognized for this list.") } } @@ -45,6 +45,6 @@ glance.list <- function(x, ...) { if (all(optim_elems %in% names(x))) { glance_optim(x, ...) } else { - stop("No glance method recognized for this list.", call. = FALSE) + cli::cli_abort("No {.fn glance} method recognized for this list.") } } diff --git a/R/lmtest.R b/R/lmtest.R index 7528e93fa..fcfb8c76c 100644 --- a/R/lmtest.R +++ b/R/lmtest.R @@ -114,8 +114,16 @@ glance.coeftest <- function(x, ...) { logLik = sprintf("%.3f", logLik(x)), AIC = AIC(x), BIC = BIC(x), nobs = nobs(x) ) - rlang::inform("Original model not retained as part of coeftest object. For additional model summary information (r.squared, df, etc.), consider passing `glance.coeftest()` an object where the underlying model has been saved, i.e.`lmtest::coeftest(..., save = TRUE)`.", - .frequency = "once", .frequency_id = "glance_coeftest_inform" + cli::cli_inform( + c( + "Original model not retained as part of coeftest object.", + "i" = "For additional model summary information (r.squared, df, etc.), + consider passing {.fn glance.coeftest} an object where the + underlying model has been saved, i.e. + {.code lmtest::coeftest(..., save = TRUE)}." + ), + .frequency = "once", + .frequency_id = "glance_coeftest_inform" ) } diff --git a/R/margins.R b/R/margins.R index ecaf781e6..430cdbb2e 100644 --- a/R/margins.R +++ b/R/margins.R @@ -87,7 +87,7 @@ tidy.margins <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { error = function(e) { mutate( ., dplyr::across(dplyr::all_of(at_vars), as.character), - message("Warning: `at.value` column coerced to character.") + cli::cli_warn("The {.field at.value} column was coerced to character.") ) %>% tidyr::pivot_longer(dplyr::all_of(at_vars), names_to = "at.variable", values_to = "at.value") } diff --git a/R/mass-polr.R b/R/mass-polr.R index 8ff4df306..eb63095ce 100644 --- a/R/mass-polr.R +++ b/R/mass-polr.R @@ -70,8 +70,10 @@ tidy.polr <- function(x, conf.int = FALSE, conf.level = 0.95, if (length(p) == length(terms)) { ret <- dplyr::left_join(ret, tibble::tibble(term = terms, p.value = p), by = "term") } else { - message("p-values can presently only be returned for models that contain - no categorical variables with more than two levels") + cli::cli_inform( + "p-values can presently only be returned for models that contain + no categorical variables with more than two levels." + ) ret$p.value <- NA } } diff --git a/R/mclust.R b/R/mclust.R index 45c811166..decdab5d2 100644 --- a/R/mclust.R +++ b/R/mclust.R @@ -107,7 +107,7 @@ augment.Mclust <- function(x, data = NULL, ...) { if (is.null(data)) { data <- x$data } else if (!(is.data.frame(data) || is.matrix(data))) { - stop("`data` must be a data frame or matrix.", call. = FALSE) + cli::cli_abort("{.arg data} must be a data frame or matrix.") } as_augment_tibble(data) %>% diff --git a/R/mediation.R b/R/mediation.R index 2bb9a7661..687e682af 100644 --- a/R/mediation.R +++ b/R/mediation.R @@ -36,10 +36,11 @@ tidy.mediate <- function(x, conf.int = FALSE, conf.level = .95, ...) { check_ellipses("exponentiate", "tidy", "mediate", ...) if (inherits(x, "psych")) { - stop( - "No tidy method for objects of class `mediate` from the `psych` package. ", - "The `tidy.mediate` method is intended for `mediate` objects from the `mediation` package." - ) + cli::cli_abort(c( + "No tidy method for objects of class {.cls mediate} from the {.pkg psych} package.", + "i" = "The {.fn tidy.mediate} method is intended for {.cls mediate} objects + from the {.pkg mediation} package." + )) } d0 <- d1 <- z0 <- z1 <- d0.sims <- d1.sims <- z0.sims <- NULL diff --git a/R/mgcv.R b/R/mgcv.R index 2cb6eb20d..63311a223 100644 --- a/R/mgcv.R +++ b/R/mgcv.R @@ -46,10 +46,10 @@ tidy.gam <- function(x, parametric = FALSE, conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE, ...) { if (!parametric && conf.int) { - message("Confidence intervals only available for parametric terms.") + cli::cli_inform("Confidence intervals only available for parametric terms.") } if (!parametric && exponentiate) { - message("Exponentiating coefficients only available for parametric terms.") + cli::cli_inform("Exponentiating coefficients only available for parametric terms.") } if (parametric) { px <- summary(x)$p.table diff --git a/R/null-and-default.R b/R/null-and-default.R index 511810154..4e8eb77d0 100644 --- a/R/null-and-default.R +++ b/R/null-and-default.R @@ -29,15 +29,15 @@ augment.NULL <- function(x, ...) tibble() #' @export tidy.default <- function(x, ...) { - stop("No tidy method for objects of class ", class(x)[1], call. = FALSE) + cli::cli_abort("No {.fn tidy} method for objects of class {.cls {class(x)}}.") } #' @export glance.default <- function(x, ...) { - stop("No glance method for objects of class ", class(x)[1], call. = FALSE) + cli::cli_abort("No {.fn glance} method for objects of class {.cls {class(x)}}.") } #' @export augment.default <- function(x, ...) { - stop("No augment method for objects of class ", class(x)[1], call. = FALSE) + cli::cli_abort("No {.fn augment} method for objects of class {.cls {class(x)}}.") } diff --git a/R/quantreg-rqs.R b/R/quantreg-rqs.R index 5cbb1f44f..6ffaca3b4 100644 --- a/R/quantreg-rqs.R +++ b/R/quantreg-rqs.R @@ -41,10 +41,13 @@ tidy.rqs <- function(x, se.type = "rank", conf.int = FALSE, #' @export glance.rqs <- function(x, ...) { - stop("`glance` cannot handle objects of class 'rqs',", - " i.e. models with more than one tau value. Please", - " use a purrr `map`-based workflow with 'rq' models instead.", - call. = FALSE + cli::cli_abort( + c( + "{.fn glance} cannot handle objects of class {.cls rqs}, + i.e. models with more than one tau value.", + "i" = "Please use a {.pkg purrr} {.fn map}-based workflow with + {.cls rq} models instead." + ) ) } diff --git a/R/robust-glmrob.R b/R/robust-glmrob.R index 82a36ac76..cf02f3293 100644 --- a/R/robust-glmrob.R +++ b/R/robust-glmrob.R @@ -37,15 +37,13 @@ tidy.glmRob <- function(x, ...) { #' #' @export augment.glmRob <- function(x, ...) { - stop( - paste0( - "`augment.glmRob` has been deprecated as the robust package", - "doesn't provide the functionality necessary to implement ", - "an augment method. Please see the augment method for ", - "glmrob objects from robustbase." - ), - call. = FALSE - ) + cli::cli_abort(c( + "{.fn augment.glmRob} has been deprecated as the {.pkg robust} package + doesn't provide the functionality necessary to implement + an augment method.", + "i" = "Please see the augment method for {.cls glmrob} objects from + {.pkg robustbase}." + )) invisible(TRUE) } diff --git a/R/speedglm-speedlm.R b/R/speedglm-speedlm.R index 0fc451fb4..27e50e1c9 100644 --- a/R/speedglm-speedlm.R +++ b/R/speedglm-speedlm.R @@ -111,9 +111,9 @@ augment.speedlm <- function(x, data = model.frame(x), newdata = NULL, ...) { no_fitted <- is.null(x$linear.predictors) && is.null(x$fitted.values) if (default_data_arg && no_fitted) { - stop( - "Must specify `data` argument or refit speedglm with `fitted = TRUE`.", - call. = FALSE + cli::cli_abort( + "Must specify {.arg data} argument or refit with + {.code fitted = TRUE}." ) } diff --git a/R/stats-anova.R b/R/stats-anova.R index c30f8e684..14dc1aea9 100644 --- a/R/stats-anova.R +++ b/R/stats-anova.R @@ -94,10 +94,9 @@ tidy.anova <- function(x, ...) { unknown_cols <- setdiff(colnames(ret), c("term", names(renamers))) if (length(unknown_cols) > 0) { - warning( - "The following column names in ANOVA output were not ", - "recognized or transformed: ", - paste(unknown_cols, collapse = ", ") + cli::cli_warn( + "The column name{?s} {.field {unknown_cols}} in ANOVA output {?was/were} + not recognized or transformed." ) } diff --git a/R/stats-factanal.R b/R/stats-factanal.R index 3b1240caa..6d8789224 100644 --- a/R/stats-factanal.R +++ b/R/stats-factanal.R @@ -96,12 +96,11 @@ augment.factanal <- function(x, data, ...) { # Check scores were computed if (is.null(scores)) { - stop( - "Cannot augment factanal objects fit with `scores = 'none'`.", - call. = FALSE + cli::cli_abort( + 'Cannot augment {.cls factanal} objects fit with {.code scores = "none"}.' ) } - + # Place relevant values into a tidy data frame if (has_rownames(scores)) { tidy_df <- data.frame(.rownames = rownames(scores), data.frame(scores)) %>% diff --git a/R/stats-glm.R b/R/stats-glm.R index 402b5d9e4..828ae5f90 100644 --- a/R/stats-glm.R +++ b/R/stats-glm.R @@ -168,10 +168,13 @@ warn_on_appropriated_glm_class <- function(x) { warn_on_glm2 <- function(x) { if (!is.null(x$method) & is.character(x$method)) { if (x$method == "glm.fit2") { - warning( - "The supplied model object seems to be outputted from the glm2 ", - "package. Tidiers for glm2 output are currently not ", - "maintained; please use caution in interpreting broom output." + cli::cli_warn( + c( + "{.arg x} seems to be outputted from the {.pkg glm2} package.", + "i" = "Tidiers for {.pkg glm2} output are currently not maintained; + please use caution in interpreting {.pkg broom} output." + ), + call = NULL ) } } @@ -181,11 +184,14 @@ warn_on_glm2 <- function(x) { # stanreg objects subclass glm, glm tidiers error out (uninformatively), # and the maintained stanreg tidiers live in broom.mixed. -warn_on_stanreg <- function(x) { +warn_on_stanreg <- function(x, call = caller_env()) { if (!is.null(x$stan_function)) { - stop( - "The supplied model object seems to be outputted from the rstanarm ", - "package. Tidiers for mixed model output now live in the broom.mixed package." + cli::cli_abort( + c( + "{.arg x} seems to be outputted from the {.pkg rstanarm} package.", + "i" = "Tidiers for mixed model output now live in {.pkg broom.mixed}." + ), + call = call ) } diff --git a/R/stats-htest.R b/R/stats-htest.R index 89d435bd8..e6fd80ba4 100644 --- a/R/stats-htest.R +++ b/R/stats-htest.R @@ -68,7 +68,7 @@ tidy.htest <- function(x, ...) { if (length(x$parameter) > 1) { ret$parameter <- NULL if (is.null(names(x$parameter))) { - warning("Multiple unnamed parameters in hypothesis test; dropping them") + cli::cli_warn("Multiple unnamed parameters in hypothesis test; dropping them.") } else { # rename num df to num.df and denom df to denom.df np <- names(x$parameter) @@ -76,11 +76,8 @@ tidy.htest <- function(x, ...) { np <- stringr::str_replace(np, "denom df", "den.df") names(x$parameter) <- np - message( - "Multiple parameters; naming those columns ", - paste(np, collapse = ", ") - ) - + cli::cli_inform("Multiple parameters; naming those columns {np}.") + ret <- append(ret, x$parameter, after = 1) } } @@ -133,9 +130,8 @@ augment.htest <- function(x, ...) { return(augment_chisq_test(x, ...)) } - stop( - "Augment is only defined for chi squared hypothesis tests.", - call. = FALSE + cli::cli_abort( + "{.fn augment.htest} is only defined for chi squared hypothesis tests." ) } diff --git a/R/stats-prcomp.R b/R/stats-prcomp.R index 05ba82058..614c3e606 100644 --- a/R/stats-prcomp.R +++ b/R/stats-prcomp.R @@ -96,7 +96,7 @@ #' @family svd tidiers tidy.prcomp <- function(x, matrix = "u", ...) { if (length(matrix) > 1) { - stop("Must select a single matrix to tidy.", call. = FALSE) + cli::cli_abort("Must select a single matrix to tidy.") } MATRIX <- c( diff --git a/R/survival-survfit.R b/R/survival-survfit.R index 4aa5c8b46..87673f66b 100644 --- a/R/survival-survfit.R +++ b/R/survival-survfit.R @@ -120,10 +120,10 @@ tidy.survfit <- function(x, ...) { #' glance.survfit <- function(x, ...) { if (inherits(x, "survfitms")) { - stop("Cannot construct a glance of a multi-state survfit object.") + cli::cli_abort("Cannot {.fn glance} a multi-state {.cls survfit} object.") } if (!is.null(x$strata)) { - stop("Cannot construct a glance of a multi-strata survfit object.") + cli::cli_abort("Cannot {.fn glance} a multi-strata {.cls survfit} object.") } s <- summary(x, ...) diff --git a/R/utilities.R b/R/utilities.R index 687f55dfc..4a35290c3 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -36,20 +36,24 @@ exponentiate <- function(data, col = "estimate") { #' -as_augment_tibble <- function(data) { +as_augment_tibble <- function(data, arg = caller_arg(data), call = caller_env()) { if (inherits(data, "matrix") & is.null(colnames(data))) { - stop( - "The supplied `data`/`newdata` argument was an unnamed matrix. ", - "Please supply a matrix or dataframe with column names." - ) + cli::cli_abort(c( + "{.arg {arg}} is an unnamed matrix.", + "i" = "Please supply a matrix or data frame with column names." + )) } tryCatch( df <- as_tibble(data), error = function(cnd) { - stop("Could not coerce data to `tibble`. Try explicitly passing a", - "dataset to either the `data` or `newdata` argument.", - call. = FALSE + cli::cli_abort( + c( + "Could not coerce {.arg {arg}} to a tibble.", + "i" = "Try explicitly passing a data frame to either the {.arg data} or + {.arg newdata} argument." + ), + call = call ) } ) @@ -86,7 +90,10 @@ is_cran_check <- function() { #' @noRd as_tidy_tibble <- function(x, new_names = NULL, new_column = "term") { if (!is.null(new_names) && length(new_names) != ncol(x)) { - stop("newnames must be NULL or have length equal to number of columns") + cli::cli_abort( + "{.arg new names} must be {.code NULL} or have length equal to + number of columns ({ncol(data)})." + ) } ret <- x @@ -164,9 +171,9 @@ as_glance_tibble <- function(..., na_types) { cols <- list(...) if (length(cols) != stringr::str_length(na_types)) { - stop( - "The number of columns provided does not match the number of ", - "column types provided." + cli::cli_abort( + "The number of columns provided does not match the number of + column {.emph types} provided." ) } @@ -305,10 +312,12 @@ augment_columns <- function(x, data, newdata = NULL, type, type.predict = type, if (inherits(na_action, "exclude")) { # check if values are missing if (length(stats::residuals(x)) > nrow(data)) { - warning( - "When fitting with na.exclude, rows with NA in ", - "original data will be dropped unless those rows are provided ", - "in 'data' argument" + cli::cli_warn( + c( + "When fitting with {.code na.exclude}, rows with {.code NA}s in + original data will be dropped unless those rows are provided + in the {.arg data} argument." + ) ) } } @@ -362,10 +371,10 @@ response <- function(object, newdata = NULL, has_response) { res } -data_error <- function(cnd) { - stop( - "Must specify either `data` or `newdata` argument.", - call. = FALSE +data_error <- function(cnd, call = caller_env()) { + cli::cli_abort( + "Must specify either {.arg data} or {.arg newdata} argument.", + call = call ) } diff --git a/R/vars.R b/R/vars.R index c86fe68a6..b796cd7f9 100644 --- a/R/vars.R +++ b/R/vars.R @@ -45,7 +45,10 @@ tidy.varest <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { # `vars` does not define a `confint` method and does not calculate CIs if (isTRUE(conf.int)) { - warning("Confidence intervals are not supported for `varest` objects. The `conf.level` argument will be ignored.") + cli::cli_warn(c( + "Confidence intervals are not supported for {.cls varest} objects.", + "i" = "The {.arg conf.level} argument will be ignored." + )) } s <- summary(x) diff --git a/tests/testthat/_snaps/drc.md b/tests/testthat/_snaps/drc.md index 298f97b88..4b002c60d 100644 --- a/tests/testthat/_snaps/drc.md +++ b/tests/testthat/_snaps/drc.md @@ -3,7 +3,7 @@ Code augment(mod) Condition - Error: + Error in `augment()`: ! Must specify either `data` or `newdata` argument. --- @@ -11,6 +11,6 @@ Code augment(mod2) Condition - Error: + Error in `augment()`: ! Must specify either `data` or `newdata` argument. diff --git a/tests/testthat/_snaps/ergm.md b/tests/testthat/_snaps/ergm.md index 3a555b1ff..36781873f 100644 --- a/tests/testthat/_snaps/ergm.md +++ b/tests/testthat/_snaps/ergm.md @@ -3,21 +3,22 @@ Code tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) Condition - Warning in `tidy.ergm()`: - Exponentiating but model didn't use log or logit link. + Warning: + Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. --- Code td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE) Condition - Warning in `tidy.ergm()`: - Exponentiating but model didn't use log or logit link. + Warning: + Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. # glance.ergm Code gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE) Message - Though `glance` was supplied `mcmc = TRUE`, the model was not fittedusing MCMC, so the corresponding columns will be omitted. + Though `glance()` was supplied `mcmc = TRUE`, the model was not fitted using MCMC, + i The corresponding columns will be omitted. diff --git a/tests/testthat/_snaps/fixest.md b/tests/testthat/_snaps/fixest.md index 5052b4272..7c44b5153 100644 --- a/tests/testthat/_snaps/fixest.md +++ b/tests/testthat/_snaps/fixest.md @@ -3,25 +3,25 @@ Code augment(res_fenegbin, df) Condition - Error in `augment.fixest()`: - ! augment is only supported for fixest models estimated with feols, feglm, or femlm - (supplied model used fenegbin) + Error in `augment()`: + ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. + i Supplied model used `fenegbin()`. --- Code augment(res_feNmlm, df) Condition - Error in `augment.fixest()`: - ! augment is only supported for fixest models estimated with feols, feglm, or femlm - (supplied model used feNmlm) + Error in `augment()`: + ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. + i Supplied model used `feNmlm()`. --- Code augment(res_fepois, df) Condition - Error in `augment.fixest()`: - ! augment is only supported for fixest models estimated with feols, feglm, or femlm - (supplied model used fepois) + Error in `augment()`: + ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. + i Supplied model used `fepois()`. diff --git a/tests/testthat/_snaps/geepack.md b/tests/testthat/_snaps/geepack.md index aecec1329..dc85995bc 100644 --- a/tests/testthat/_snaps/geepack.md +++ b/tests/testthat/_snaps/geepack.md @@ -3,6 +3,6 @@ Code td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE) Condition - Warning in `tidy.geeglm()`: - Exponentiating coefficients, but model did not use a log or logit link function + Warning: + Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. diff --git a/tests/testthat/_snaps/joineRML.md b/tests/testthat/_snaps/joineRML.md index e58ff78d1..c9c74ef28 100644 --- a/tests/testthat/_snaps/joineRML.md +++ b/tests/testthat/_snaps/joineRML.md @@ -3,14 +3,15 @@ Code tidy(mjoint_fit, boot_se = "cat") Condition - Error: - ! `boot_se` argument must be a `bootSE` object. + Error in `tidy()`: + ! `boot_se` must be a object. # augment.mjoint Code augment(mjoint_fit, data = NULL) Condition - Error: - ! `data` argument is NULL. Try specifying `data` manually. + Error in `augment()`: + ! `data` argument is `NULL`. + i Try specifying `data` manually. diff --git a/tests/testthat/_snaps/lfe.md b/tests/testthat/_snaps/lfe.md index 3b0a7acbf..2e4f4c367 100644 --- a/tests/testthat/_snaps/lfe.md +++ b/tests/testthat/_snaps/lfe.md @@ -3,23 +3,23 @@ Code .res <- tidy(fit, robust = TRUE) Condition - Warning in `tidy.felm()`: - - The "robust" argument has been deprecated in tidy.felm and will be ignored. Please use the "se.type" argument instead. + Warning: + The `robust` argument has been deprecated in `tidy.felm()` and will be ignored. + i Please use the `se.type` argument instead. # glance.felm Code glance(fit_multi) Condition - Error: - ! Glance does not support linear models with multiple responses. + Error in `glance()`: + ! `felm()` models with multiple responses are not supported. # augment.felm Code augment(fit_multi) Condition - Error: - ! Augment does not support linear models with multiple responses. + Error in `augment()`: + ! `felm()` models with multiple responses are not supported. diff --git a/tests/testthat/_snaps/list-xyz.md b/tests/testthat/_snaps/list-xyz.md index a431f6a17..2a5bd1a9e 100644 --- a/tests/testthat/_snaps/list-xyz.md +++ b/tests/testthat/_snaps/list-xyz.md @@ -3,22 +3,22 @@ Code tidy(b) Condition - Error: - ! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. + Error in `tidy_xyz()`: + ! To tidy an xyz list, the length of element `x` must equal the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. --- Code tidy(c) Condition - Error: - ! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. + Error in `tidy_xyz()`: + ! To tidy an xyz list, the length of element `x` must equal the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. --- Code tidy(d) Condition - Error: - ! To tidy an xyz list, `z` must be a matrix. + Error in `tidy_xyz()`: + ! `z` must be a matrix. diff --git a/tests/testthat/_snaps/list.md b/tests/testthat/_snaps/list.md index 6e515f0ad..5ccb184a1 100644 --- a/tests/testthat/_snaps/list.md +++ b/tests/testthat/_snaps/list.md @@ -3,14 +3,14 @@ Code tidy(nl) Condition - Error: - ! No tidy method recognized for this list. + Error in `tidy()`: + ! No `tidy()` method recognized for this list. --- Code glance(nl) Condition - Error: - ! No glance method recognized for this list. + Error in `glance()`: + ! No `glance()` method recognized for this list. diff --git a/tests/testthat/_snaps/mclust.md b/tests/testthat/_snaps/mclust.md index a1f0cd876..820e76799 100644 --- a/tests/testthat/_snaps/mclust.md +++ b/tests/testthat/_snaps/mclust.md @@ -3,6 +3,6 @@ Code augment(fit, 1:10) Condition - Error: + Error in `augment()`: ! `data` must be a data frame or matrix. diff --git a/tests/testthat/_snaps/null-and-default.md b/tests/testthat/_snaps/null-and-default.md index db98dd9a7..40d0b0e2b 100644 --- a/tests/testthat/_snaps/null-and-default.md +++ b/tests/testthat/_snaps/null-and-default.md @@ -3,118 +3,118 @@ Code td <- tidy(raw(1)) Condition - Error: - ! No tidy method for objects of class raw + Error in `tidy()`: + ! No `tidy()` method for objects of class . --- Code glance(x) Condition - Error: - ! No glance method for objects of class foo + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance(x) Condition - Error: - ! No glance method for objects of class foo + Error in `glance()`: + ! No `glance()` method for objects of class . # glance.default Code glance(TRUE) Condition - Error: - ! No glance method for objects of class logical + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance(1) Condition - Error: - ! No glance method for objects of class numeric + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance(1L) Condition - Error: - ! No glance method for objects of class integer + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance("a") Condition - Error: - ! No glance method for objects of class character + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance(x) Condition - Error: - ! No glance method for objects of class foo + Error in `glance()`: + ! No `glance()` method for objects of class . --- Code glance(x) Condition - Error: - ! No glance method for objects of class foo + Error in `glance()`: + ! No `glance()` method for objects of class . # augment.default Code augment(TRUE) Condition - Error: - ! No augment method for objects of class logical + Error in `augment()`: + ! No `augment()` method for objects of class . --- Code augment(1) Condition - Error: - ! No augment method for objects of class numeric + Error in `augment()`: + ! No `augment()` method for objects of class . --- Code augment(1L) Condition - Error: - ! No augment method for objects of class integer + Error in `augment()`: + ! No `augment()` method for objects of class . --- Code augment("a") Condition - Error: - ! No augment method for objects of class character + Error in `augment()`: + ! No `augment()` method for objects of class . --- Code augment(x) Condition - Error: - ! No augment method for objects of class foo + Error in `augment()`: + ! No `augment()` method for objects of class . --- Code augment(x) Condition - Error: - ! No augment method for objects of class foo + Error in `augment()`: + ! No `augment()` method for objects of class . diff --git a/tests/testthat/_snaps/quantreg-rqs.md b/tests/testthat/_snaps/quantreg-rqs.md index 2d49adce8..cbad54e70 100644 --- a/tests/testthat/_snaps/quantreg-rqs.md +++ b/tests/testthat/_snaps/quantreg-rqs.md @@ -3,6 +3,7 @@ Code glance(fit) Condition - Error: - ! `glance` cannot handle objects of class 'rqs', i.e. models with more than one tau value. Please use a purrr `map`-based workflow with 'rq' models instead. + Error in `glance()`: + ! `glance()` cannot handle objects of class , i.e. models with more than one tau value. + i Please use a purrr `map()`-based workflow with models instead. diff --git a/tests/testthat/_snaps/speedglm-speedglm.md b/tests/testthat/_snaps/speedglm-speedglm.md index 692cea16b..017f04119 100644 --- a/tests/testthat/_snaps/speedglm-speedglm.md +++ b/tests/testthat/_snaps/speedglm-speedglm.md @@ -3,6 +3,6 @@ Code augment(fit) Condition - Error: - ! No augment method for objects of class speedglm + Error in `augment()`: + ! No `augment()` method for objects of class . diff --git a/tests/testthat/_snaps/speedglm-speedlm.md b/tests/testthat/_snaps/speedglm-speedlm.md index 41d159317..7ca5c4c59 100644 --- a/tests/testthat/_snaps/speedglm-speedlm.md +++ b/tests/testthat/_snaps/speedglm-speedlm.md @@ -3,6 +3,6 @@ Code augment(fit3) Condition - Error: - ! Must specify `data` argument or refit speedglm with `fitted = TRUE`. + Error in `augment()`: + ! Must specify `data` argument or refit with `fitted = TRUE`. diff --git a/tests/testthat/_snaps/stats-anova.md b/tests/testthat/_snaps/stats-anova.md index 5fe756eda..928733885 100644 --- a/tests/testthat/_snaps/stats-anova.md +++ b/tests/testthat/_snaps/stats-anova.md @@ -3,6 +3,6 @@ Code .res <- tidy(loess_anova) Condition - Warning in `tidy.anova()`: - The following column names in ANOVA output were not recognized or transformed: ENP + Warning: + The column name ENP in ANOVA output was not recognized or transformed. diff --git a/tests/testthat/_snaps/stats-factanal.md b/tests/testthat/_snaps/stats-factanal.md index df76c7b7a..364943cb3 100644 --- a/tests/testthat/_snaps/stats-factanal.md +++ b/tests/testthat/_snaps/stats-factanal.md @@ -3,6 +3,6 @@ Code augment(fit_none) Condition - Error: - ! Cannot augment factanal objects fit with `scores = 'none'`. + Error in `augment()`: + ! Cannot augment objects fit with `scores = "none"`. diff --git a/tests/testthat/_snaps/stats-htest.md b/tests/testthat/_snaps/stats-htest.md index 2c4289d88..a491fb628 100644 --- a/tests/testthat/_snaps/stats-htest.md +++ b/tests/testthat/_snaps/stats-htest.md @@ -3,29 +3,29 @@ Code td <- tidy(ot) Message - Multiple parameters; naming those columns num.df, den.df + Multiple parameters; naming those columns num.df and den.df. # augment.htest (chi squared test) Code augment(tt) Condition - Error: - ! Augment is only defined for chi squared hypothesis tests. + Error in `augment()`: + ! `augment.htest()` is only defined for chi squared hypothesis tests. --- Code augment(wt) Condition - Error: - ! Augment is only defined for chi squared hypothesis tests. + Error in `augment()`: + ! `augment.htest()` is only defined for chi squared hypothesis tests. --- Code augment(ct) Condition - Error: - ! Augment is only defined for chi squared hypothesis tests. + Error in `augment()`: + ! `augment.htest()` is only defined for chi squared hypothesis tests. diff --git a/tests/testthat/_snaps/stats-prcomp.md b/tests/testthat/_snaps/stats-prcomp.md index 9cdf08014..96225bce8 100644 --- a/tests/testthat/_snaps/stats-prcomp.md +++ b/tests/testthat/_snaps/stats-prcomp.md @@ -3,6 +3,6 @@ Code tidy(pc, matrix = c("d", "u")) Condition - Error: + Error in `tidy()`: ! Must select a single matrix to tidy. diff --git a/tests/testthat/_snaps/survival-survfit.md b/tests/testthat/_snaps/survival-survfit.md index c9a64b004..e44cc1b1f 100644 --- a/tests/testthat/_snaps/survival-survfit.md +++ b/tests/testthat/_snaps/survival-survfit.md @@ -3,14 +3,14 @@ Code glance(sfit) Condition - Error in `glance.survfit()`: - ! Cannot construct a glance of a multi-strata survfit object. + Error in `glance()`: + ! Cannot `glance()` a multi-strata object. --- Code glance(fit2) Condition - Error in `glance.survfit()`: - ! Cannot construct a glance of a multi-state survfit object. + Error in `glance()`: + ! Cannot `glance()` a multi-state object. diff --git a/tests/testthat/_snaps/vars.md b/tests/testthat/_snaps/vars.md index 7917bb49e..a685225cc 100644 --- a/tests/testthat/_snaps/vars.md +++ b/tests/testthat/_snaps/vars.md @@ -3,6 +3,7 @@ Code .res <- tidy(fit, conf.int = TRUE) Condition - Warning in `tidy.varest()`: - Confidence intervals are not supported for `varest` objects. The `conf.level` argument will be ignored. + Warning: + Confidence intervals are not supported for objects. + i The `conf.level` argument will be ignored.