rasterfile <- system.file("external/test.grd", package="raster")
st <- stack(rasterfile)
# now adding the same file multiple times, in most cases you would add different files
# this generates warnings, but it is not an error
st <- addFiles(st, c(rasterfile, rasterfile))
rs <- raster(rasterfile)
st <- addLayer(st, c(rs, rs))
st
st <- dropLayer(st, c(3, 5))
nlayers(st)
Run the code above in your browser using DataLab