Examples for 'terra::deepcopy'


Deep copy

Aliases: deepcopy deepcopy,SpatRaster-method deepcopy,SpatVector-method

Keywords: methods spatial

### ** Examples

r <- rast(ncols=10, nrows=10, nl=3)
tm <- as.Date("2001-05-03") + 1:3
time(r) <- tm
time(r)
[1] "2001-05-04" "2001-05-05" "2001-05-06"
x <- r
time(x) <- tm + 365
time(x)
[1] "2002-05-04" "2002-05-05" "2002-05-06"
time(r)
[1] "2002-05-04" "2002-05-05" "2002-05-06"
y <- deepcopy(r)
time(y) <- tm - 365
time(y)
[1] "2000-05-04" "2000-05-05" "2000-05-06"
time(r)
[1] "2002-05-04" "2002-05-05" "2002-05-06"
# or make a new object like this
z <- rast(r)
time(z) <- tm
time(z)
[1] "2001-05-04" "2001-05-05" "2001-05-06"
time(r)
[1] "2002-05-04" "2002-05-05" "2002-05-06"

[Package terra version 1.5-34 Index]