I have set up a script that crops a fixed SpatialPointsDataFrame based on an area that the user defines. These are then plotted using MapView. However, if the SpatialPointsDataFrame comes back empty as no points are within the user defined area, MapView fails with the error:
Error in (function (classes, fdef, mtable): unable to find an inherited method for function ‘mapView’ for signature ‘"NULL"’
I have tried using ignoreNULL as defined in Leaflet, but it doesn't seem to work.
Example Code Below (ignoring the steps to crop the data):
##load required package
library(mapview)
##create variable with point
breweries_A <- breweries
##create variable with no points
breweries_B <- NULL
##create variable ready to plot as one map
m <- mapview(breweries_A) + mapview(breweries_B)
I am hoping there is a simple bit of code I can add to get MapView to ignore an empty dataset.