From d2d65807b10612050d82fc91dfabe726ca103b20 Mon Sep 17 00:00:00 2001 From: Mike Mahoney Date: Thu, 25 Apr 2024 17:00:43 -0400 Subject: [PATCH] Fix CHECK errors --- DESCRIPTION | 2 +- NAMESPACE | 8 +++ R/geom_spatial_rgb.R | 8 +++ man/geom_spatial_rgb.Rd | 82 +++++++++++++++++++----- tests/testthat/_snaps/add_bbox_buffer.md | 10 +-- tests/testthat/test-combine_overlays.R | 1 + 6 files changed, 89 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe8ba2f..ac762b2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,6 +48,6 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Depends: R (>= 2.10) diff --git a/NAMESPACE b/NAMESPACE index 72cfef1..4fd814a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,10 @@ S3method(add_bbox_buffer,Raster) S3method(add_bbox_buffer,SpatRaster) S3method(add_bbox_buffer,sf) +S3method(geom_spatial_rgb_internal,RasterStack) +S3method(geom_spatial_rgb_internal,SpatRaster) +S3method(geom_spatial_rgb_internal,character) +S3method(geom_spatial_rgb_internal,default) S3method(get_tiles,Raster) S3method(get_tiles,SpatRaster) S3method(get_tiles,list) @@ -11,6 +15,10 @@ S3method(get_tiles,sfc) S3method(set_bbox_side_length,Raster) S3method(set_bbox_side_length,SpatRaster) S3method(set_bbox_side_length,sf) +S3method(stat_spatial_rgb_internal,RasterStack) +S3method(stat_spatial_rgb_internal,SpatRaster) +S3method(stat_spatial_rgb_internal,character) +S3method(stat_spatial_rgb_internal,default) export(StatSpatialRGB) export(add_bbox_buffer) export(combine_overlays) diff --git a/R/geom_spatial_rgb.R b/R/geom_spatial_rgb.R index eaa0d83..14ed0b9 100644 --- a/R/geom_spatial_rgb.R +++ b/R/geom_spatial_rgb.R @@ -129,6 +129,7 @@ geom_spatial_rgb_internal <- function(data = NULL, } +#' @export geom_spatial_rgb_internal.character <- function(data = NULL, mapping = NULL, stat = "spatialRGB", @@ -156,6 +157,7 @@ geom_spatial_rgb_internal.character <- function(data = NULL, ) } +#' @export geom_spatial_rgb_internal.RasterStack <- function(data = NULL, mapping = NULL, stat = "spatialRGB", @@ -182,6 +184,7 @@ geom_spatial_rgb_internal.RasterStack <- function(data = NULL, ) } +#' @export geom_spatial_rgb_internal.SpatRaster <- function(data = NULL, mapping = NULL, stat = "spatialRGB", @@ -222,6 +225,7 @@ geom_spatial_rgb_internal.SpatRaster <- function(data = NULL, ) } +#' @export geom_spatial_rgb_internal.default <- function(data = NULL, mapping = NULL, stat = "spatialRGB", @@ -325,6 +329,7 @@ stat_spatial_rgb_internal <- function(data = NULL, UseMethod("stat_spatial_rgb_internal") } +#' @export stat_spatial_rgb_internal.character <- function(data = NULL, mapping = NULL, geom = "raster", @@ -349,6 +354,7 @@ stat_spatial_rgb_internal.character <- function(data = NULL, ) } +#' @export stat_spatial_rgb_internal.RasterStack <- function(data = NULL, mapping = NULL, geom = "raster", @@ -367,6 +373,7 @@ stat_spatial_rgb_internal.RasterStack <- function(data = NULL, ) } +#' @export stat_spatial_rgb_internal.SpatRaster <- function(data = NULL, mapping = NULL, geom = "raster", @@ -399,6 +406,7 @@ stat_spatial_rgb_internal.SpatRaster <- function(data = NULL, ) } +#' @export stat_spatial_rgb_internal.default <- function(data = NULL, mapping = NULL, geom = "raster", diff --git a/man/geom_spatial_rgb.Rd b/man/geom_spatial_rgb.Rd index 627f80a..983fccc 100644 --- a/man/geom_spatial_rgb.Rd +++ b/man/geom_spatial_rgb.Rd @@ -51,20 +51,59 @@ the raster to a data frame and assume the raster bands are in RGB order If a length-1 character vector, this function will attempt to load the object via \link[terra:rast]{terra::rast}.} -\item{stat}{The statistical transformation to use on the data for this -layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the -stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than -\code{"stat_count"})} - -\item{position}{Position adjustment, either as a string naming the adjustment -(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a -position adjustment function. Use the latter if you need to change the -settings of the adjustment.} - -\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are -often aesthetics, used to set an aesthetic to a fixed value, like -\code{colour = "red"} or \code{size = 3}. They may also be parameters -to the paired geom/stat.} +\item{stat}{The statistical transformation to use on the data for this layer. +When using a \verb{geom_*()} function to construct a layer, the \code{stat} +argument can be used the override the default coupling between geoms and +stats. The \code{stat} argument accepts the following: +\itemize{ +\item A \code{Stat} ggproto subclass, for example \code{StatCount}. +\item A string naming the stat. To give the stat as a string, strip the +function name of the \code{stat_} prefix. For example, to use \code{stat_count()}, +give the stat as \code{"count"}. +\item For more information and other ways to specify the stat, see the +\link[ggplot2:layer_stats]{layer stat} documentation. +}} + +\item{position}{A position adjustment to use on the data for this layer. This +can be used in various ways, including to prevent overplotting and +improving the display. The \code{position} argument accepts the following: +\itemize{ +\item The result of calling a position function, such as \code{position_jitter()}. +This method allows for passing extra arguments to the position. +\item A string naming the position adjustment. To give the position as a +string, strip the function name of the \code{position_} prefix. For example, +to use \code{position_jitter()}, give the position as \code{"jitter"}. +\item For more information and other ways to specify the position, see the +\link[ggplot2:layer_positions]{layer position} documentation. +}} + +\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}'s \code{params} argument. These +arguments broadly fall into one of 4 categories below. Notably, further +arguments to the \code{position} argument, or aesthetics that are required +can \emph{not} be passed through \code{...}. Unknown arguments that are not part +of the 4 categories below are ignored. +\itemize{ +\item Static aesthetics that are not mapped to a scale, but are at a fixed +value and apply to the layer as a whole. For example, \code{colour = "red"} +or \code{linewidth = 3}. The geom's documentation has an \strong{Aesthetics} +section that lists the available options. The 'required' aesthetics +cannot be passed on to the \code{params}. Please note that while passing +unmapped aesthetics as vectors is technically possible, the order and +required length is not guaranteed to be parallel to the input data. +\item When constructing a layer using +a \verb{stat_*()} function, the \code{...} argument can be used to pass on +parameters to the \code{geom} part of the layer. An example of this is +\code{stat_density(geom = "area", outline.type = "both")}. The geom's +documentation lists which parameters it can accept. +\item Inversely, when constructing a layer using a +\verb{geom_*()} function, the \code{...} argument can be used to pass on parameters +to the \code{stat} part of the layer. An example of this is +\code{geom_area(stat = "density", adjust = 0.5)}. The stat's documentation +lists which parameters it can accept. +\item The \code{key_glyph} argument of \code{\link[ggplot2:layer]{layer()}} may also be passed on through +\code{...}. This can be one of the functions described as +\link[ggplot2:draw_key]{key glyphs}, to change the display of the layer in the legend. +}} \item{hjust, vjust}{horizontal and vertical justification of the grob. Each justification value should be a number between 0 and 1. Defaults to 0.5 @@ -91,9 +130,18 @@ the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.} If \code{NULL}, attempts to infer proper values from data -- if all RGB values are <= 1 then 1, <= 255 then 255, and otherwise 65535.} -\item{geom}{The geometric object to use to display the data, either as a -\code{ggproto} \code{Geom} subclass or as a string naming the geom stripped of the -\code{geom_} prefix (e.g. \code{"point"} rather than \code{"geom_point"})} +\item{geom}{The geometric object to use to display the data for this layer. +When using a \verb{stat_*()} function to construct a layer, the \code{geom} argument +can be used to override the default coupling between stats and geoms. The +\code{geom} argument accepts the following: +\itemize{ +\item A \code{Geom} ggproto subclass, for example \code{GeomPoint}. +\item A string naming the geom. To give the geom as a string, strip the +function name of the \code{geom_} prefix. For example, to use \code{geom_point()}, +give the geom as \code{"point"}. +\item For more information and other ways to specify the geom, see the +\link[ggplot2:layer_geoms]{layer geom} documentation. +}} } \description{ \code{geom_spatial_rgb} and \code{stat_spatial_rgb} allow users to plot three-band RGB diff --git a/tests/testthat/_snaps/add_bbox_buffer.md b/tests/testthat/_snaps/add_bbox_buffer.md index 09302fc..91b24b8 100644 --- a/tests/testthat/_snaps/add_bbox_buffer.md +++ b/tests/testthat/_snaps/add_bbox_buffer.md @@ -2,7 +2,8 @@ Code set_bbox_side_length(df_sf, 8000) - Warning + Condition + Warning: No CRS associated with input data. i Assuming EPSG:4326. Output @@ -11,13 +12,14 @@ Dimension: XY Bounding box: xmin: -73.97357 ymin: 44.07662 xmax: -73.87337 ymax: 44.14857 Geodetic CRS: WGS 84 - Message + Message POLYGON ((-73.97357 44.07662, -73.87337 44.0766... --- Code set_bbox_side_length(df_sf, 8000, error_crs = TRUE) - Error - No CRS associated with input data. + Condition + Error in `add_bbox_buffer()`: + ! No CRS associated with input data. diff --git a/tests/testthat/test-combine_overlays.R b/tests/testthat/test-combine_overlays.R index 0d9a949..064ada0 100644 --- a/tests/testthat/test-combine_overlays.R +++ b/tests/testthat/test-combine_overlays.R @@ -1,4 +1,5 @@ test_that("combine_overlays works", { + skip_if_not_installed("tiff") x_tmp <- tempfile(fileext = ".png") y_tmp <- tempfile(fileext = ".png")