I'm using raster::calc
to make some calculations and write the output to GeoTiff in just one go. But I'd like to set the layer name of the output before writing to disk. I'm trying to do this by using setNames
inside the function but it's now working. How can I change layer name inside a raster::calc
call that saves the file to disk?
Here is a simple reprex
library(raster)
#> Loading required package: sp
r <- raster(ncols=36, nrows=18)
r[] <- 1:ncell(r)
names(r) <- 'my_name_is'
r2 <- calc(r, function(x) {
y <- x * 10
y <- setNames(y, 'my_name_is')
})
names(r2)
#> [1] "layer"
Created on 2020-05-07 by the reprex package (v0.3.0)