From 6ec6d1b0a0c9a28a8709f00fdfedcb21809ae854 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Fri, 6 Sep 2024 13:44:40 +0200 Subject: [PATCH] Fix build on 3.6 --- NAMESPACE | 1 - R/plot_patchwork.R | 2 +- R/wrap_table.R | 2 +- R/zzz.R | 22 ++++++++++++++++++++-- man/wrap_table.Rd | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index da67d88..4b05ea8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -144,7 +144,6 @@ importFrom(grid,seekViewport) importFrom(grid,unit) importFrom(grid,unit.c) importFrom(grid,unit.pmax) -importFrom(grid,unitType) importFrom(grid,upViewport) importFrom(grid,valid.just) importFrom(grid,viewport) diff --git a/R/plot_patchwork.R b/R/plot_patchwork.R index 661e0d0..daa4069 100644 --- a/R/plot_patchwork.R +++ b/R/plot_patchwork.R @@ -1036,7 +1036,7 @@ find_strip_pos <- function(gt) { } 'inside' } -#' @importFrom grid unitType + set_panel_dimensions <- function(gt, panels, widths, heights, fixed_asp, design) { width_ind <- seq(PANEL_COL, by = TABLE_COLS, length.out = length(widths)) height_ind <- seq(PANEL_ROW, by = TABLE_ROWS, length.out = length(heights)) diff --git a/R/wrap_table.R b/R/wrap_table.R index 90e0ac4..8f49ef9 100644 --- a/R/wrap_table.R +++ b/R/wrap_table.R @@ -58,7 +58,7 @@ #' # the size of the area they occupy #' p2 <- ggplot(airquality) + #' geom_boxplot(aes(y = month.name[Month], x = Temp)) + -#' scale_y_discrete(name = NULL, limits = month.name[5:9], guide = "none") +#' scale_y_discrete(name = NULL, limits = month.name[9:5], guide = "none") #' #' wrap_table(gt_tab, space = "fixed") + p2 #' diff --git a/R/zzz.R b/R/zzz.R index 0d0b3e7..5cd12e9 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -32,6 +32,24 @@ register_s3_method <- function(pkg, generic, class, fun = NULL) { } ) } -on_load( + +unitType <- function(x) { + unit <- attr(x, "unit") + if (!is.null(unit)) { + return(unit) + } + if (is.list(x) && is.unit(x[[1]])) { + unit <- vapply(x, unitType, character(1)) + return(unit) + } else if ("fname" %in% names(x)) { + return(x$fname) + } + rep("", length(x)) # we're only interested in simple units for now +} + +on_load({ register_s3_method("vdiffr", "print_plot", "patchwork") -) + if ("unitType" %in% getNamespaceExports("grid")) { + unitType <- grid::unitType + } +}) diff --git a/man/wrap_table.Rd b/man/wrap_table.Rd index 5aec9d7..5cbbb05 100644 --- a/man/wrap_table.Rd +++ b/man/wrap_table.Rd @@ -77,7 +77,7 @@ p1 + wrap_table(gt_tab, panel = "full") # the size of the area they occupy p2 <- ggplot(airquality) + geom_boxplot(aes(y = month.name[Month], x = Temp)) + - scale_y_discrete(name = NULL, limits = month.name[5:9], guide = "none") + scale_y_discrete(name = NULL, limits = month.name[9:5], guide = "none") wrap_table(gt_tab, space = "fixed") + p2 \dontshow{\}) # examplesIf}