Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


quickPlot (version 1.0.2)

numLayers: Find the number of layers in an object

Description

A unified function for raster::nlayers, terra::nlyrs, or lists of these. Default function returns 1L for all other classes.

Usage

numLayers(x)

Value

The number of layers in the object.

Arguments

x

An object or list of objects.

Author

Eliot McIntire

Examples

Run this code
library(terra)

files <- system.file("maps", package = "quickPlot")
files <- dir(files, full.names = TRUE, pattern = "tif")
maps <- lapply(files, function(x) rast(x))
names(maps) <- sapply(basename(files), function(x) {
  strsplit(x, split = "\\.")[[1]][1]
})
stck <- rast(maps)

numLayers(maps)
numLayers(stck)

Run the code above in your browser using DataLab