From 6e8bc63022401c020aff77c0b96e703607139e78 Mon Sep 17 00:00:00 2001 From: Ryan Hafen Date: Wed, 29 Nov 2023 10:47:24 -0800 Subject: [PATCH] Fixes for submission --- R/facet_geo.R | 6 ++++-- man/grid_preview.Rd | 4 +++- tests/testthat/test-grids.R | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/facet_geo.R b/R/facet_geo.R index 44c7c92..aa91ffa 100644 --- a/R/facet_geo.R +++ b/R/facet_geo.R @@ -173,6 +173,7 @@ plot.facet_geo <- function(x, ...) { #' @param x a data frame containing a grid #' @param label the column name in \code{x} that should be used for text labels in the grid plot #' @param label_raw the column name in the optional SpatialPolygonsDataFrame attached to \code{x} that should be used for text labels in the raw geography plot +#' @param do_plot should the grid preview be plotted? #' @export #' @importFrom ggplot2 ggplot geom_rect geom_text aes xlim ylim #' @importFrom gridExtra grid.arrange @@ -180,7 +181,7 @@ plot.facet_geo <- function(x, ...) { #' @examples #' grid_preview(us_state_grid2) #' grid_preview(eu_grid1, label = "name") -grid_preview <- function(x, label = NULL, label_raw = NULL) { +grid_preview <- function(x, label = NULL, label_raw = NULL, do_plot = TRUE) { if (!inherits(x, "geofacet_grid")) x <- get_grid(x) @@ -221,7 +222,8 @@ grid_preview <- function(x, label = NULL, label_raw = NULL) { p2 <- plot_geo_raw(spdf, label = label_raw) p <- gridExtra::grid.arrange(p2, p, nrow = 1) } else { - suppressWarnings(plot(p)) + if (do_plot) + plot(p) } invisible(p) } diff --git a/man/grid_preview.Rd b/man/grid_preview.Rd index 9ee7a2f..6ee5fba 100644 --- a/man/grid_preview.Rd +++ b/man/grid_preview.Rd @@ -4,7 +4,7 @@ \alias{grid_preview} \title{Plot a preview of a grid} \usage{ -grid_preview(x, label = NULL, label_raw = NULL) +grid_preview(x, label = NULL, label_raw = NULL, do_plot = TRUE) } \arguments{ \item{x}{a data frame containing a grid} @@ -12,6 +12,8 @@ grid_preview(x, label = NULL, label_raw = NULL) \item{label}{the column name in \code{x} that should be used for text labels in the grid plot} \item{label_raw}{the column name in the optional SpatialPolygonsDataFrame attached to \code{x} that should be used for text labels in the raw geography plot} + +\item{do_plot}{should the grid preview be plotted?} } \description{ Plot a preview of a grid diff --git a/tests/testthat/test-grids.R b/tests/testthat/test-grids.R index 3abc501..a7ef4a2 100644 --- a/tests/testthat/test-grids.R +++ b/tests/testthat/test-grids.R @@ -4,5 +4,5 @@ library(ggplot2) test_that("grids all load and work correctly", { for (grd in .valid_grids) - expect_no_error(grid_preview(grd)) + expect_no_error(prv <- grid_preview(grd, do_plot = FALSE)) })