Learn R Programming

terra (version 1.5-21)

inplace: Change values in-place

Description

These "in-place" replacement methods assign new value to an object without making a copy. That is efficient, but if there is a copy of the object that you made by standard assignment (e.g. with y <- x), that copy is also changed.

set.names is the in-place replacement version of names<-. set.ext is the in-place replacement version of ext<- set.values is the in-place replacement version of [<- set.cats is the in-place replacement version of categories set.crs is the in-place replacement version of crs<-

Usage

# S4 method for SpatRaster
set.names(x, value, index=1:nlyr(x), validate=FALSE)
# S4 method for SpatRasterDataset
set.names(x, value, index=1:length(x), validate=FALSE)
# S4 method for SpatVector
set.names(x, value, index=1:ncol(x), validate=FALSE)

# S4 method for SpatRaster set.ext(x, value) # S4 method for SpatVector set.ext(x, value)

# S4 method for SpatRaster set.crs(x, value) # S4 method for SpatVector set.crs(x, value)

# S4 method for SpatRaster set.values(x, cells, values)

# S4 method for SpatRaster set.cats(x, layer=1, value, index)

Arguments

x

SpatRaster

value

character (set.names). For set.cats: a data.frame with columns (value, category) or vector with category names

index

positive integer indicating layer(s) to assign a name to, or the index to select the active category

validate

logical. Make names valid and/or unique?

cells

cell numbers

values

replacement values

layer

positive integer indicating to which layer to you want to assign these categories

Examples

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

x <- s
set.names(s, c("e", "f", "g"))
names(s)
names(x)

set.ext(x, c(0,180,0,90))

set.values(x, 1:10, 5)
# }

Run the code above in your browser using DataLab