From 128ddb51ef90eb25f8813ce2bbc11bacd64a0dcd Mon Sep 17 00:00:00 2001 From: olivroy Date: Mon, 22 Jul 2024 13:13:04 -0400 Subject: [PATCH] Use cli instead of crayon. (fix spacing --- DESCRIPTION | 1 - NAMESPACE | 5 ----- R/interact_plot.R | 13 ++++++++----- R/johnson_neyman.R | 14 ++++++++------ R/simple_margins.R | 10 ++++++---- R/simple_slopes.R | 12 +++++++----- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6bb934f..fe0084a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,6 @@ License: MIT + file LICENSE Encoding: UTF-8 Imports: ggplot2 (>= 3.5.0), - crayon, cli, generics, jtools (>= 2.0.3), diff --git a/NAMESPACE b/NAMESPACE index 0ff33ff..7b90ef3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,11 +37,6 @@ import(jtools) import(rlang) importFrom(cli,cat_rule) importFrom(cli,rule) -importFrom(crayon,bold) -importFrom(crayon,inverse) -importFrom(crayon,italic) -importFrom(crayon,red) -importFrom(crayon,underline) importFrom(generics,glance) importFrom(generics,tidy) importFrom(stats,aggregate) diff --git a/R/interact_plot.R b/R/interact_plot.R index b32388f..a14dab3 100755 --- a/R/interact_plot.R +++ b/R/interact_plot.R @@ -443,11 +443,14 @@ interact_plot <- function(model, pred, modx, modx.values = NULL, mod2 = NULL, # Check for factor predictor and send to plot_cat() if so if (!is.numeric(d[[pred]])) { # Warn users that this is kinda janky - msg_wrap("Detected factor predictor. Plotting with cat_plot() instead. - Consult cat_plot() documentation (?cat_plot) for full details - on how to specify models with categorical predictors. If you - experience errors or unexpected results, try using cat_plot() - directly.") + cli::cli_inform(c( + x = "Detected factor predictor.", + i = "Plotting with cat_plot() instead.", + i = "See {.help interactions::cat_plot} for full details on + how to specify models with categorical predictors.", + i = "If you experience errors or unexpected results, try using + cat_plot() directly." + )) # Gather arguments for plot_cat() args <- list(predictions = pm, pred = pred, modx = modx, mod2 = mod2, data = d, modx.values = modxvals2, mod2.values = mod2vals2, diff --git a/R/johnson_neyman.R b/R/johnson_neyman.R index 5de285b..b238b06 100644 --- a/R/johnson_neyman.R +++ b/R/johnson_neyman.R @@ -603,7 +603,6 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05, } #' @export -#' @importFrom crayon bold inverse underline print.johnson_neyman <- function(x, ...) { @@ -611,9 +610,9 @@ print.johnson_neyman <- function(x, ...) { # Describe whether sig values are inside/outside the interval if (atts$inside == FALSE) { - inout <- inverse("OUTSIDE") + inout <- cli::style_inverse("OUTSIDE") } else { - inout <- inverse("INSIDE") + inout <- cli::style_inverse("INSIDE") } b_format <- num_print(x$bounds, atts$digits) @@ -622,13 +621,16 @@ print.johnson_neyman <- function(x, ...) { pmsg <- paste("p <", alpha) # Print the output - cat(bold(underline("JOHNSON-NEYMAN INTERVAL")), "\n\n") + cli::cat_line( + cli::style_bold(cli::style_underline("JOHNSON-NEYMAN INTERVAL")), + "\n" + ) if (all(is.finite(x$bounds))) { cat_wrap("When ", atts$modx, " is ", inout, " the interval [", b_format[1], ", ", b_format[2], "], the slope of ", atts$pred, " is ", pmsg, ".", brk = "\n\n") - cat_wrap(italic("Note: The range of observed values of", atts$modx, - "is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n") + cat_wrap(cli::style_italic("Note: The range of observed values of ", atts$modx, + " is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n") } else { cat_wrap("The Johnson-Neyman interval could not be found. Is the p value for your interaction term below diff --git a/R/simple_margins.R b/R/simple_margins.R index baf96cf..8dc8475 100644 --- a/R/simple_margins.R +++ b/R/simple_margins.R @@ -247,7 +247,6 @@ sim_margins <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, #' @export #' @importFrom cli cat_rule rule -#' @importFrom crayon red bold italic print.sim_margins <- function(x, ...) { @@ -308,7 +307,10 @@ print.sim_margins <- function(x, ...) { } # Clearly label simple slopes - cat(bold(underline("SIMPLE MARGINS")), "\n\n") + cli::cat_line( + cli::style_bold(cli::style_underline("SIMPLE MARGINS")), + "\n" + ) for (i in seq_along(x$modx.values)) { @@ -329,8 +331,8 @@ print.sim_margins <- function(x, ...) { modx_label <- paste0(m[i, x$modx]) } - cat(italic(paste0("Average marginal effect of ", x$pred, " when ", - x$modx, " = ", modx_label, ": \n\n"))) + cli::cat_line(cli::style_italic(paste0("Average marginal effect of ", x$pred, " when ", + x$modx, " = ", modx_label, ": \n"))) print(md_table(slopes, digits = x$digits, format = "pandoc", row.names = FALSE, sig.digits = FALSE)) diff --git a/R/simple_slopes.R b/R/simple_slopes.R index 4076f61..b6fc4b1 100644 --- a/R/simple_slopes.R +++ b/R/simple_slopes.R @@ -764,7 +764,6 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, #' @export #' @importFrom cli cat_rule rule -#' @importFrom crayon red bold italic print.sim_slopes <- function(x, ...) { @@ -848,7 +847,10 @@ print.sim_slopes <- function(x, ...) { } # Clearly label simple slopes - cat(bold(underline("SIMPLE SLOPES ANALYSIS")), "\n\n") + cli::cat_line( + cli::style_bold(cli::style_underline("SIMPLE SLOPES ANALYSIS")), + "\n" + ) for (i in seq_along(x$modx.values)) { @@ -871,7 +873,7 @@ print.sim_slopes <- function(x, ...) { # Print conditional intercept if (x$cond.int == TRUE | fac_pred == TRUE) { pred_lab <- if (fac_pred) {slopes[["Coef."]]} else {x$pred} - cat(italic(paste0("When ", x$modx, " = ", modx_label, ": \n\n"))) + cli::cat_line(cli::style_italic(paste0("When ", x$modx, " = ", modx_label, ": \n"))) if (x$cond.int) { ints <- m$ints[i,2:ncol(m$slopes)] slopes <- as.data.frame(rbind(slopes, ints)) @@ -884,8 +886,8 @@ print.sim_slopes <- function(x, ...) { print(md_table(slopes %not% "Coef.", digits = x$digits, format = "pandoc", sig.digits = FALSE)) } else { - cat(italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ", - modx_label, ": \n\n"))) + cli::cat_line(cli::style_italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ", + modx_label, ": \n"))) print(md_table(slopes, digits = x$digits, format = "pandoc", row.names = FALSE, sig.digits = FALSE)) }