diff --git a/R/alignpatch-inset.R b/R/alignpatch-inset.R index 9ea09998..9bfadf78 100644 --- a/R/alignpatch-inset.R +++ b/R/alignpatch-inset.R @@ -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") } @@ -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) } @@ -114,7 +115,7 @@ patch.gList <- function(x, ...) { #' @family patch methods #' @export patch.ggplot <- function(x, ...) { - ggplotGrob(x) + ggplotGrob(x, ...) } #' @inherit patch.grob @@ -125,7 +126,7 @@ patch.ggplot <- function(x, ...) { #' @family patch methods #' @export patch.patch_ggplot <- function(x, ...) { - ggalignGrob(x) + ggalignGrob(x, ...) } #' @inherit patch.grob @@ -133,7 +134,7 @@ patch.patch_ggplot <- function(x, ...) { #' @family patch methods #' @export patch.alignpatches <- function(x, ...) { - ggalignGrob(x) + ggalignGrob(x, ...) } #' @inherit patch.grob @@ -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 @@ -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 @@ -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) } @@ -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") +} diff --git a/R/fortify-upset.R b/R/fortify-upset.R index c367c3d6..5ad3b2e3 100644 --- a/R/fortify-upset.R +++ b/R/fortify-upset.R @@ -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") } @@ -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))) }) diff --git a/R/ggfree.R b/R/ggfree.R index 7833ccab..933f279e 100644 --- a/R/ggfree.R +++ b/R/ggfree.R @@ -31,7 +31,6 @@ #' geom_point() #' @export ggfree <- function(data = waiver(), ..., size = NULL, active = NULL) { - rlang::check_dots_used() UseMethod("ggfree", data) } @@ -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 diff --git a/R/layout-.R b/R/layout-.R index dcaf9421..396f367e 100644 --- a/R/layout-.R +++ b/R/layout-.R @@ -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") } @@ -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, ...) { diff --git a/R/raster-magick.R b/R/raster-magick.R index 77e9fbbc..bc207fbd 100644 --- a/R/raster-magick.R +++ b/R/raster-magick.R @@ -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 @@ -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")) { @@ -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, @@ -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 diff --git a/man/dot-raster_magick.Rd b/man/dot-raster_magick.Rd deleted file mode 100644 index fdd56f6e..00000000 --- a/man/dot-raster_magick.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/raster-magick.R -\name{.raster_magick} -\alias{.raster_magick} -\title{Rasterize the input object} -\usage{ -.raster_magick(x, magick = NULL, ...) -} -\arguments{ -\item{x}{An object to rasterize, can be a \code{\link[grid:grid.grob]{grob()}}, -\code{\link[ggplot2:layer]{layer()}}, \code{\link[ggplot2:ggplot]{ggplot()}}, or a list of such -objects.} - -\item{magick}{A function (purrr-style formula is accepted) that takes an -\code{\link[magick:editing]{image_read()}} object as input and returns an object -compatible with \code{\link[grDevices:as.raster]{as.raster()}}. You can use any of -the \verb{image_*()} functions from the \strong{magick} package to process the raster -image.} - -\item{...}{Not used currently.} -} -\value{ -An object with the same class of the input. -} -\description{ -An internal function designed to implement the functionality of -\code{raster_magick()}. It assumes the input arguments are valid and does not -perform any additional checks. -} -\keyword{internal} diff --git a/man/raster_magick_interal.Rd b/man/raster_magick_interal.Rd new file mode 100644 index 00000000..f6dbab95 --- /dev/null +++ b/man/raster_magick_interal.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/raster-magick.R +\name{raster_magick_interal} +\alias{raster_magick_interal} +\alias{.raster_magick} +\alias{.raster_magick.Layer} +\alias{.raster_magick.list} +\alias{.raster_magick.ggplot} +\alias{.raster_magick.grob} +\alias{.raster_magick.gList} +\alias{.raster_magick.ggalignRasterMagick} +\alias{.raster_magick.zeroGrob} +\alias{.raster_magick.default} +\title{Rasterize the input object} +\usage{ +.raster_magick(x, ...) + +\method{.raster_magick}{Layer}(x, ...) + +\method{.raster_magick}{list}(x, ...) + +\method{.raster_magick}{ggplot}(x, ...) + +\method{.raster_magick}{grob}(x, magick = NULL, ..., res = NULL, interpolate = FALSE) + +\method{.raster_magick}{gList}(x, magick = NULL, ..., res = NULL, interpolate = FALSE) + +\method{.raster_magick}{ggalignRasterMagick}(x, magick = NULL, ..., res = NULL, interpolate = FALSE) + +\method{.raster_magick}{zeroGrob}(x, ...) + +\method{.raster_magick}{default}(x, ...) +} +\arguments{ +\item{x}{An object to rasterize, can be a \code{\link[grid:grid.grob]{grob()}}, +\code{\link[ggplot2:layer]{layer()}}, \code{\link[ggplot2:ggplot]{ggplot()}}, or a list of such +objects.} + +\item{...}{Not used currently.} + +\item{magick}{A function (purrr-style formula is accepted) that takes an +\code{\link[magick:editing]{image_read()}} object as input and returns an object +compatible with \code{\link[grDevices:as.raster]{as.raster()}}. You can use any of +the \verb{image_*()} functions from the \strong{magick} package to process the raster +image.} + +\item{res}{An integer sets the desired resolution in pixels.} + +\item{interpolate}{ + A logical value indicating whether to linearly interpolate the + image (the alternative is to use nearest-neighbour interpolation, + which gives a more blocky result). + } +} +\value{ +An object with the same class of the input. +} +\description{ +An internal function designed to implement the functionality of +\code{raster_magick()}. It assumes the input arguments are valid and does not +perform any additional checks. +} +\keyword{internal}