Learn R Programming

terra (version 0.4-3)

names: Names of Spat objects

Description

Get or set the names of the layers of a SpatRaster or the attributes of a SpatVector.

Usage

# S4 method for SpatRaster
names(x)
# S4 method for SpatRaster
names(x)<-value
# S4 method for SpatVector
names(x)
# S4 method for SpatVector
names(x)<-value

Arguments

x

SpatRaster or SpatVector

value

character (vector)

Value

character

Examples

Run this code
# NOT RUN {
s <- rast(ncols=5, nrows=5, nlyr=3)
nlyr(s)
names(s)
names(s) <- c("a", "b", "c")
names(s)

# space is not valid
names(s)[2] <- "hello world"
names(s)

# two invalid names
names(s) <- c("a", "  a  ", "3")
names(s)

# SpatVector names
f <- system.file("exdata/lux.shp", package="terra")
v <- vect(f)
names(v)
names(v) <- paste0(substr(names(v), 1, 2), "_", 1:ncol(v))
names(v)
# }

Run the code above in your browser using DataLab