Skip to content

Commit

Permalink
use check_dots_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 9, 2025
1 parent 089e2d9 commit f794010
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 55 deletions.
19 changes: 12 additions & 7 deletions R/alignpatch-inset.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ ggplot_add.patch_inset <- function(object, plot, object_name) {
#' @export
#' @keywords internal
patch <- function(x, ...) {
rlang::check_dots_used()
UseMethod("patch")
}

Expand All @@ -98,12 +97,14 @@ patch.default <- function(x, ...) {
#' @family patch methods
#' @export
patch.grob <- function(x, ...) {
rlang::check_dots_empty()
x
}

#' @export
#' @rdname patch.grob
patch.gList <- function(x, ...) {
rlang::check_dots_empty()
# gLists need to be wrapped in a grob tree
grid::grobTree(x)
}
Expand All @@ -114,7 +115,7 @@ patch.gList <- function(x, ...) {
#' @family patch methods
#' @export
patch.ggplot <- function(x, ...) {
ggplotGrob(x)
ggplotGrob(x, ...)
}

#' @inherit patch.grob
Expand All @@ -125,15 +126,15 @@ patch.ggplot <- function(x, ...) {
#' @family patch methods
#' @export
patch.patch_ggplot <- function(x, ...) {
ggalignGrob(x)
ggalignGrob(x, ...)
}

#' @inherit patch.grob
#' @seealso [`alignpatches`][align_plots]
#' @family patch methods
#' @export
patch.alignpatches <- function(x, ...) {
ggalignGrob(x)
ggalignGrob(x, ...)
}

#' @inherit patch.grob
Expand All @@ -142,7 +143,7 @@ patch.alignpatches <- function(x, ...) {
#' @export
patch.patchwork <- function(x, ...) {
rlang::check_installed("patchwork", "to make grob from patchwork")
patchwork::patchworkGrob(x)
patchwork::patchworkGrob(x, ...)
}

#' @inherit patch.grob
Expand All @@ -151,7 +152,7 @@ patch.patchwork <- function(x, ...) {
#' @export
patch.patch <- function(x, ...) {
rlang::check_installed("patchwork", "to make grob from patch")
patchwork::patchGrob(x)
patchwork::patchGrob(x, ...)
}

#' @inherit patch.grob
Expand Down Expand Up @@ -201,6 +202,7 @@ patch.function <- function(x, ..., device = NULL, name = NULL) {
#' @export
patch.recordedplot <- function(x, ..., device = NULL) {
rlang::check_installed("gridGraphics", "to make grob from recordedplot")
rlang::check_dots_empty()
gridGraphics::echoGrob(x, device = device %||% offscreen)
}

Expand Down Expand Up @@ -257,4 +259,7 @@ patch.HeatmapAnnotation <- patch.HeatmapList
#' @seealso [`pheatmap()`][pheatmap::pheatmap]
#' @family patch methods
#' @export
patch.pheatmap <- function(x, ...) .subset2(x, "gtable")
patch.pheatmap <- function(x, ...) {
rlang::check_dots_empty()
.subset2(x, "gtable")
}
2 changes: 1 addition & 1 deletion R/fortify-upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#' @export
fortify_upset <- function(data, mode = "distinct", ...) {
mode <- arg_match0(mode, c("distinct", "intersect", "union"))
rlang::check_dots_used()
UseMethod("fortify_upset")
}

Expand All @@ -34,6 +33,7 @@ fortify_upset <- function(data, mode = "distinct", ...) {
#' @family fortify_upset methods
#' @export
fortify_upset.list <- function(data, mode = "distinct", ...) {
rlang::check_dots_empty()
data <- lapply(data, function(x) {
vec_unique(vec_slice(x, !vec_detect_missing(x)))
})
Expand Down
2 changes: 1 addition & 1 deletion R/ggfree.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#' geom_point()
#' @export
ggfree <- function(data = waiver(), ..., size = NULL, active = NULL) {
rlang::check_dots_used()
UseMethod("ggfree", data)
}

Expand Down Expand Up @@ -60,6 +59,7 @@ ggfree.uneval <- function(data = waiver(), ...) {

#' @export
ggfree.ggplot <- function(data = waiver(), ..., size = NULL, active = NULL) {
rlang::check_dots_empty()
plot <- data
# In ggplot2, `waiver()` was regard to no data
data <- .subset2(plot, "data") %|w|% NULL
Expand Down
6 changes: 4 additions & 2 deletions R/layout-.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ inherit_parent_layout_theme <- function(layout, theme, spacing = NULL) {
#' @return The statistics
#' @export
ggalign_stat <- function(x, ...) {
rlang::check_dots_used()
UseMethod("ggalign_stat")
}

Expand Down Expand Up @@ -154,7 +153,10 @@ ggalign_stat.ggalign_plot <- function(x, ...) {
}

#' @export
ggalign_stat.Align <- function(x, ...) .subset2(x, "statistics")
ggalign_stat.Align <- function(x, ...) {
rlang::check_dots_empty()
.subset2(x, "statistics")
}

#' @export
ggalign_stat.default <- function(x, ...) {
Expand Down
40 changes: 26 additions & 14 deletions R/raster-magick.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ raster_magick <- function(x, magick = NULL, ...,
}
assert_number_whole(res, min = 1, allow_null = TRUE)
assert_bool(interpolate)
rlang::check_dots_used()
.raster_magick(
x = x, ..., magick = magick,
res = res, interpolate = interpolate
Expand All @@ -61,16 +60,20 @@ raster_magick <- function(x, magick = NULL, ...,
#' `raster_magick()`. It assumes the input arguments are valid and does not
#' perform any additional checks.
#' @inheritParams raster_magick
#' @name raster_magick_interal
#' @keywords internal
.raster_magick <- function(x, magick = NULL, ...) {
.raster_magick <- function(x, ...) {
UseMethod(".raster_magick")
}

#' @importFrom ggplot2 ggproto ggproto_parent
#' @importFrom rlang list2
#' @export
.raster_magick.Layer <- function(x, magick = NULL, ...) {
#' @rdname raster_magick_interal
.raster_magick.Layer <- function(x, ...) {
ggproto(
NULL, x,
.ggalign_raster_magick = list2(...),
draw_geom = function(self, data, layout) {
grobs <- ggproto_parent(x, self)$draw_geom(data, layout)
if (!inherits(layout$coord, "CoordCartesian")) {
Expand All @@ -79,26 +82,30 @@ raster_magick <- function(x, magick = NULL, ...,
)
return(grobs)
}
lapply(grobs, .raster_magick, ..., magick = magick)
inject(.raster_magick(grobs, !!!self$.ggalign_raster_magick))
}
)
}

#' @export
.raster_magick.list <- function(x, magick = NULL, ...) {
lapply(x, .raster_magick, ..., magick = magick)
#' @rdname raster_magick_interal
.raster_magick.list <- function(x, ...) {
lapply(x, .raster_magick, ...)
}

#' @export
.raster_magick.ggplot <- function(x, magick = NULL, ...) {
x$layers <- lapply(x$layers, .raster_magick, ..., magick = magick)
#' @rdname raster_magick_interal
.raster_magick.ggplot <- function(x, ...) {
x$layers <- lapply(x$layers, .raster_magick, ...)
x
}

#' @importFrom grid grob
#' @export
#' @rdname raster_magick_interal
.raster_magick.grob <- function(x, magick = NULL, ...,
res = NULL, interpolate = FALSE) {
rlang::check_dots_empty()
grob(
grob = x,
magick = magick,
Expand All @@ -110,23 +117,28 @@ raster_magick <- function(x, magick = NULL, ...,

#' @importFrom grid grob
#' @export
#' @rdname raster_magick_interal
.raster_magick.gList <- .raster_magick.grob

#' @importFrom grid editGrob
#' @export
#' @rdname raster_magick_interal
.raster_magick.ggalignRasterMagick <- function(x, magick = NULL, ...,
res = NULL,
interpolate = FALSE) {
x["magick"] <- list(magick)
x["res"] <- list(res)
x["interpolate"] <- list(interpolate)
x
rlang::check_dots_empty()
editGrob(x, magick = magick, res = res, interpolate = interpolate)
}

# there methods won't check arguments, all arguments passed will be just ignored
# directly
#' @export
.raster_magick.zeroGrob <- function(x, magick = NULL, ...) x
#' @rdname raster_magick_interal
.raster_magick.zeroGrob <- function(x, ...) x

#' @export
.raster_magick.default <- function(x, magick = NULL, ...) x
#' @rdname raster_magick_interal
.raster_magick.default <- function(x, ...) x

# preDraw:
# - makeContext
Expand Down
30 changes: 0 additions & 30 deletions man/dot-raster_magick.Rd

This file was deleted.

63 changes: 63 additions & 0 deletions man/raster_magick_interal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f794010

Please sign in to comment.