dkahle / ggmap

A package for plotting maps in R with ggplot2
763 stars 231 forks source link

ggmap has bad test for `base_layer` #334

Closed dmurdoch closed 8 months ago

dmurdoch commented 1 year ago

Reproducible Example

Example:

reprex::reprex({
    library(ggmap)
    library(ggplot2)
    ggmap(get_map(), base_layer = ggplot())
}, si = TRUE)

This example generates a warning if you run it:

Warning message:
In missing(base_layer) || base_layer == "auto" :
  'length(x) = 9 > 1' in coercion to 'logical(1)'

The problem is with the test base_layer == "auto". Since base_layer is a ggplot object, it's a list of length 9, and so that test fails.

A fix for this is to use

missing(base_layer || identical(base_layer, "auto")

or perhaps

missing(base_layer) ||
  (is.character(base_layer) && length(base_layer) == 1) && base_layer == "auto")

instead. (The second test is a bit more lenient: the argument could have names or other attributes and still pass.)

dmurdoch commented 1 year ago

A workaround that ggvoronoi has adopted (https://github.com/garretrc/ggvoronoi/pull/16) is to use inset_ggmap instead of the base_layer argument to ggmap().