Skip to contents

Function to return the length of the array in which elements are organized.

Usage

nlayers(x)

# S4 method for list
nlayers(x)

# S4 method for SpatRaster
nlayers(x)

# S4 method for VirtualArray
length(x)

# S4 method for XArray
nlayers(x)

# S4 method for RasterArray
nlayers(x)

Arguments

x

a VirtualArray-derived class object.

Value

A numeric value.

Details

The length() function returns the number elements that should be present based on the array structure itself, and not the total number of values stored in the object. As the object can contain missing values, the number of actual layers can be queried with nlayers.

Examples

ex <- rastex()
# omit third element
ex[3] <- NA
# number of elements in the RasterArray
length(ex)
#> [1] 6
# remaining number values in the stack 
length(ex@stack)
#> [1] 1
# the number of remaining layers in the RasterArray
nlayers(ex)
#> [1] 5