From 84f1e705713908f3d0efbbc6c68e52c2eac19b33 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 19 Nov 2024 23:20:00 +0100 Subject: [PATCH 1/6] Some minor clean-up --- R/global_vars.R | 17 --------------- R/plot.check_distribution.R | 10 ++++----- R/plot.check_predictions.R | 31 +++++++++++++++------------ R/plot.equivalence_test.R | 10 ++++----- R/plot.n_factors.R | 10 ++++----- R/plot.performance_simres.R | 2 +- R/plots.R | 6 +----- man/plot.see_performance_simres.Rd | 2 +- man/print.see_performance_pp_check.Rd | 4 ++-- 9 files changed, 36 insertions(+), 56 deletions(-) delete mode 100644 R/global_vars.R diff --git a/R/global_vars.R b/R/global_vars.R deleted file mode 100644 index f31ec1439..000000000 --- a/R/global_vars.R +++ /dev/null @@ -1,17 +0,0 @@ -# defining global variables and functions to appease R CMD Check - -utils::globalVariables( - names = c( - ".", - "CI_high", - "CI_low", - "estimate", - "Estimate", - "grp", - "Parameter", - "predictor", - "ROPE_Equivalence", - "x_intercept", - "y_max" - ) -) diff --git a/R/plot.check_distribution.R b/R/plot.check_distribution.R index 40338131a..e146220cc 100644 --- a/R/plot.check_distribution.R +++ b/R/plot.check_distribution.R @@ -108,10 +108,9 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) { theme_lucid() if (panel) { - insight::check_if_installed("patchwork") - return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2)) + p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2) } else { - return(list(p1, p2, p3)) + list(p1, p2, p3) } } @@ -184,9 +183,8 @@ plot.see_check_distribution_numeric <- function(x, theme_lucid() if (panel) { - insight::check_if_installed("patchwork") - return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L)) + p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L) } else { - return(list(p1, p2, p3)) + list(p1, p2, p3) } } diff --git a/R/plot.check_predictions.R b/R/plot.check_predictions.R index 4d9453892..4d12296e4 100644 --- a/R/plot.check_predictions.R +++ b/R/plot.check_predictions.R @@ -96,7 +96,7 @@ print.see_performance_pp_check <- function(x, line_alpha = 0.15, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), - type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + type = "density", x_limits = NULL, ...) { orig_x <- x @@ -107,7 +107,10 @@ print.see_performance_pp_check <- function(x, if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) { type <- plot_type } else { - type <- match.arg(type) + type <- insight::validate_argument( + type, + c("density", "discrete_dots", "discrete_interval", "discrete_both") + ) } if (!inherits(x, "data_plot")) { @@ -153,7 +156,7 @@ plot.see_performance_pp_check <- function(x, line_alpha = 0.15, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), - type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + type = "density", x_limits = NULL, ...) { orig_x <- x @@ -164,7 +167,10 @@ plot.see_performance_pp_check <- function(x, if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) { # nolint type <- plot_type } else { - type <- match.arg(type) + type <- insight::validate_argument( + type, + c("density", "discrete_dots", "discrete_interval", "discrete_both") + ) } if (!inherits(x, "data_plot")) { @@ -451,7 +457,7 @@ plot.see_performance_pp_check <- function(x, subtitle <- "Model-predicted points should be close to observed data points" } - p <- p + + p + ggplot2::scale_y_continuous() + ggplot2::scale_color_manual(values = c( "Observed data" = colors[1], @@ -470,8 +476,6 @@ plot.see_performance_pp_check <- function(x, color = ggplot2::guide_legend(reverse = TRUE), size = ggplot2::guide_legend(reverse = TRUE) ) - - return(p) } @@ -543,13 +547,12 @@ plot.see_performance_pp_check <- function(x, .plot_pp_check_range <- function(x, size_bar = 0.7, colors = unname(social_colors(c("green", "blue")))) { - original <- - data.frame( - x = c(min(x$y), max(x$y)), - group = factor(c("Minimum", "Maximum"), levels = c("Minimum", "Maximum")), - color = "Observed data", - stringsAsFactors = FALSE - ) + original <- data.frame( + x = c(min(x$y), max(x$y)), + group = factor(c("Minimum", "Maximum"), levels = c("Minimum", "Maximum")), + color = "Observed data", + stringsAsFactors = FALSE + ) replicated <- rbind( data.frame( diff --git a/R/plot.equivalence_test.R b/R/plot.equivalence_test.R index 3a3eca517..2607d2e2c 100644 --- a/R/plot.equivalence_test.R +++ b/R/plot.equivalence_test.R @@ -399,11 +399,11 @@ plot.see_equivalence_test_lm <- function(x, p <- ggplot( x, aes( - y = Parameter, - x = Estimate, - xmin = CI_low, - xmax = CI_high, - colour = ROPE_Equivalence + y = .data$Parameter, + x = .data$Estimate, + xmin = .data$CI_low, + xmax = .data$CI_high, + colour = .data$ROPE_Equivalence ) ) + annotate( diff --git a/R/plot.n_factors.R b/R/plot.n_factors.R index bb2b63843..064a753e8 100644 --- a/R/plot.n_factors.R +++ b/R/plot.n_factors.R @@ -139,19 +139,19 @@ plot.see_n_factors <- function(x, segment_data <- data.frame(x_intercept = x$x[which.max(x$y)], y_max = max(x$y, na.rm = TRUE)) p <- ggplot(x, aes(x = .data$x, y = .data$y)) + geom_area(fill = flat_colors("grey")) + - geom_segment( + geom_segment( data = segment_data, aes( - x = x_intercept, - xend = x_intercept, + x = .data$x_intercept, + xend = .data$x_intercept, y = 0, - yend = y_max + yend = .data$y_max ), color = flat_colors("red") ) + geom_point( data = segment_data, - aes(x = x_intercept, y = y_max), + aes(x = .data$x_intercept, y = .data$y_max), color = flat_colors("red") ) + scale_x_continuous(breaks = 1:max(x$x, na.rm = TRUE)) + diff --git a/R/plot.performance_simres.R b/R/plot.performance_simres.R index a8d96d010..ed2901e40 100644 --- a/R/plot.performance_simres.R +++ b/R/plot.performance_simres.R @@ -14,7 +14,7 @@ #' #' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html). #' -#' @examplesIf insight::check_if_installed("performance", "0.10.9.7") && require("glmmTMB") && require("qqplotr") && require("DHARMa") +#' @examplesIf require("glmmTMB") && require("qqplotr") && require("DHARMa") #' data(Salamanders, package = "glmmTMB") #' model <- glmmTMB::glmmTMB( #' count ~ mined + spp + (1 | site), diff --git a/R/plots.R b/R/plots.R index 996427084..f7fd14512 100644 --- a/R/plots.R +++ b/R/plots.R @@ -64,8 +64,6 @@ plots <- function(..., subtitle = NULL, caption = NULL, theme = NULL) { - insight::check_if_installed("patchwork") - # Add tags if (!is.null(tags)) { if (length(tags) == 1L) { @@ -81,7 +79,7 @@ plots <- function(..., } } - pw <- patchwork::wrap_plots(..., nrow = n_rows, ncol = n_columns, guides = guides) + + patchwork::wrap_plots(..., nrow = n_rows, ncol = n_columns, guides = guides) + patchwork::plot_annotation( tag_levels = tags, tag_prefix = tag_prefix, @@ -92,8 +90,6 @@ plots <- function(..., caption = caption, theme = theme ) - - return(pw) } diff --git a/man/plot.see_performance_simres.Rd b/man/plot.see_performance_simres.Rd index 8457c3a5d..f68332ae4 100644 --- a/man/plot.see_performance_simres.Rd +++ b/man/plot.see_performance_simres.Rd @@ -56,7 +56,7 @@ The \code{plot()} method for the \code{performance::check_residuals()} resp. \code{performance::simulate_residuals()} function. } \examples{ -\dontshow{if (insight::check_if_installed("performance", "0.10.9.7") && require("glmmTMB") && require("qqplotr") && require("DHARMa")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("glmmTMB") && require("qqplotr") && require("DHARMa")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(Salamanders, package = "glmmTMB") model <- glmmTMB::glmmTMB( count ~ mined + spp + (1 | site), diff --git a/man/print.see_performance_pp_check.Rd b/man/print.see_performance_pp_check.Rd index 7e3d88349..d80921e43 100644 --- a/man/print.see_performance_pp_check.Rd +++ b/man/print.see_performance_pp_check.Rd @@ -16,7 +16,7 @@ line_alpha = 0.15, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), - type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + type = "density", x_limits = NULL, ... ) @@ -32,7 +32,7 @@ line_alpha = 0.15, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), - type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + type = "density", x_limits = NULL, ... ) From 1cf95786ef4f0613fb4adf587e4c77f628826683 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 21:46:43 +0100 Subject: [PATCH 2/6] fix --- R/plot.equivalence_test.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/plot.equivalence_test.R b/R/plot.equivalence_test.R index 083367918..73eae78cc 100644 --- a/R/plot.equivalence_test.R +++ b/R/plot.equivalence_test.R @@ -137,7 +137,7 @@ plot.see_equivalence_test <- function(x, insight::check_if_installed("ggridges") - p <- ggplot(tmp, aes(x = estimate, y = predictor, fill = grp)) + + p <- ggplot(tmp, aes(x = .data$estimate, y = .data$predictor, fill = .data$grp)) + annotate( "rect", xmin = .rope[1], @@ -281,7 +281,7 @@ plot.see_equivalence_test_df <- function(x, insight::check_if_installed("ggridges") - p <- ggplot(tmp, aes(x = estimate, y = predictor, fill = grp)) + + p <- ggplot(tmp, aes(x = .data$estimate, y = .data$predictor, fill = .data$grp)) + annotate( "rect", xmin = .rope[1], From b50b9950a32e785373b5bf28bd4884e277b5f009 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 21:47:46 +0100 Subject: [PATCH 3/6] revert change --- R/plot.check_distribution.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/plot.check_distribution.R b/R/plot.check_distribution.R index 16737aa5d..27c3ab0f4 100644 --- a/R/plot.check_distribution.R +++ b/R/plot.check_distribution.R @@ -108,9 +108,10 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) { theme_lucid() if (panel) { - p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2) + insight::check_if_installed("patchwork") + return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2)) } else { - list(p1, p2, p3) + return(list(p1, p2, p3)) } } From 8bd3efab38e98d5914c58fa834f6bf2aaf3b3093 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 21:49:35 +0100 Subject: [PATCH 4/6] fix --- R/plot.check_distribution.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/plot.check_distribution.R b/R/plot.check_distribution.R index 27c3ab0f4..baea7bbf5 100644 --- a/R/plot.check_distribution.R +++ b/R/plot.check_distribution.R @@ -108,7 +108,6 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) { theme_lucid() if (panel) { - insight::check_if_installed("patchwork") return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2)) } else { return(list(p1, p2, p3)) @@ -183,8 +182,8 @@ plot.see_check_distribution_numeric <- function(x, theme_lucid() if (panel) { - p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L) + return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L)) } else { - list(p1, p2, p3) + return(list(p1, p2, p3)) } } From b63c828a2080f110c9e5a9a70a695ac5b87cf54e Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 22:02:30 +0100 Subject: [PATCH 5/6] revert --- R/plot.check_distribution.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/plot.check_distribution.R b/R/plot.check_distribution.R index baea7bbf5..e2f1cdb9e 100644 --- a/R/plot.check_distribution.R +++ b/R/plot.check_distribution.R @@ -108,6 +108,7 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) { theme_lucid() if (panel) { + insight::check_if_installed("patchwork") return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2)) } else { return(list(p1, p2, p3)) @@ -182,6 +183,7 @@ plot.see_check_distribution_numeric <- function(x, theme_lucid() if (panel) { + insight::check_if_installed("patchwork") return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L)) } else { return(list(p1, p2, p3)) From 86c6e9ec66f27f993a23f680ee4a9d18258fd06f Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 3 Dec 2024 22:52:27 +0100 Subject: [PATCH 6/6] styler --- R/plot.n_factors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/plot.n_factors.R b/R/plot.n_factors.R index 0332b3f9e..3e647918f 100644 --- a/R/plot.n_factors.R +++ b/R/plot.n_factors.R @@ -138,7 +138,7 @@ plot.see_n_factors <- function(x, segment_data <- data.frame(x_intercept = x$x[which.max(x$y)], y_max = max(x$y, na.rm = TRUE)) p <- ggplot(x, aes(x = .data$x, y = .data$y)) + geom_area(fill = flat_colors("grey")) + - geom_segment( + geom_segment( data = segment_data, aes( x = .data$x_intercept,