Skip to content

Commit

Permalink
Use rlang and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Aug 14, 2023
1 parent 643f73b commit 94bfd3e
Show file tree
Hide file tree
Showing 17 changed files with 977 additions and 45 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Imports:
stats,
grDevices,
utils,
graphics
graphics,
rlang,
cli
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
URL: https://patchwork.data-imaginist.com, https://github.com/thomasp85/patchwork
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export(set_dim)
export(wrap_elements)
export(wrap_ggplot_grob)
export(wrap_plots)
import(cli)
import(rlang)
importFrom(ggplot2,aes)
importFrom(ggplot2,element_blank)
Expand Down
27 changes: 27 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,30 @@ GUIDE_TOP <- 5
GUIDE_BOTTOM <- 15

patchwork_namespace_link <- function() NULL

check_object <- function(x,
check_fun,
what,
...,
allow_null = FALSE,
arg = caller_arg(x),
call = caller_env()) {

if (!missing(x)) {
if (check_fun(x)) {
return(invisible(NULL))
}
if (allow_null && is_null(x)) {
return(invisible(NULL))
}
}

stop_input_type(
x,
what,
...,
allow_null = allow_null,
arg = arg,
call = call
)
}
2 changes: 1 addition & 1 deletion R/add_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ as_patchwork <- function(x) {
}
#' @export
as_patchwork.default <- function(x) {
stop('Don\'t know how to convert an object of class <', paste(class(x), collapse = ', '),'> to a patchwork', call. = FALSE)
cli_abort('Don\'t know how to convert an object of class {.cls {class(x)}} to a patchwork')
}
#' @export
as_patchwork.ggplot <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion R/arithmetic.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ NULL
if (is.null(e2)) return(e1)
if (is.null(e1)) return(e2)
if (should_autowrap(e2)) e2 <- wrap_elements(full = e2)
if (!is.ggplot(e2)) stop("Only knows how to fold ggplot objects together", call. = FALSE)
if (!is.ggplot(e2)) cli_abort("Only knows how to fold ggplot objects together")
patchwork <- new_patchwork()
if (is_patchwork(e2)) {
plot <- plot_filler()
Expand Down
4 changes: 2 additions & 2 deletions R/guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ guides_build <- function(guides, theme) {
legend.spacing.x <- theme$legend.spacing.x %||% legend.spacing
legend.box.margin <- theme$legend.box.margin %||% margin()

widths <- do.call(unit.c, lapply(guides, gtable_width))
heights <- do.call(unit.c, lapply(guides, gtable_height))
widths <- exec(unit.c, !!!lapply(guides, gtable_width))
heights <- exec(unit.c, !!!lapply(guides, gtable_height))

just <- valid.just(theme$legend.box.just)
xjust <- just[1]
Expand Down
Loading

0 comments on commit 94bfd3e

Please sign in to comment.