I changed the names of the 20 layers in my raster stack (Rstack) and then write the newly named stack to file but when I read the file back into R the names are not preserved so if I want to use the file I have to re-stack the rasters each time... Here is my code:
Rstack <- Rstack[[name]] #changing names of layers to match model filenames
writeRaster(Rstack, filename="Rstack.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
Rstack <- raster("Rstack.tif") #read in the stack
But when I try to use the "read-in" stack I get an error that the names do not match the model order names - so I then have to restack and rename if I want to use the stack which takes a long time. Is there something I am missing in writeRaster() that would preserve the names after I change them?