There are already methods for Raster* objects. This adds methods for SpatialPoints*, SpatialLines*, and SpatialPolygons*, returning an empty character vector of length 1. This function was created to give consistent, meaningful results for all classes of objects plotted by Plot.

layerNames(object)

# S4 method for ANY
layerNames(object)

Arguments

object

A Raster*, SpatialPoints*, SpatialLines*, or SpatialPolygons* object; or list of these.

Author

Eliot McIntire

Examples

library(terra)

## RasterLayer objects
files <- system.file("maps", package = "quickPlot")
files <- dir(files, full.names = TRUE, pattern = "tif")
maps <- lapply(files, function(x) terra::rast(x))
names(maps) <- sapply(basename(files), function(x) {
  strsplit(x, split = "\\.")[[1]][1]
})
layerNames(maps)
#>              DEM        forestAge      forestCover   habitatQuality 
#>            "DEM"      "forestAge"    "forestCover" "habitatQuality" 
#>      percentPine 
#>    "percentPine" 

## SpatVector objects
caribou <- terra::vect(cbind(x = stats::runif(1e2, -50, 50),
                             y = stats::runif(1e2, -50, 50)))
layerNames(caribou)
#> [1] ""