A RasterStack is a collection of RasterLayer objects with the same spatial extent and resolution. A RasterStack can be created from RasterLayer objects, or from raster files, or both. It can also be created from a SpatialPixelsDataFrame or a SpatialGridDataFrame object.

# S4 method for character
stack(x, ..., bands=NULL, varname="", native=FALSE, RAT=TRUE, quick=FALSE)

# S4 method for Raster
stack(x, ..., layers=NULL)

# S4 method for missing

# S4 method for list
stack(x, bands=NULL, native=FALSE, RAT=TRUE, ...)



filename (character), Raster* object, missing (to create an empty RasterStack), SpatialGrid*, SpatialPixels*, or list (of filenames and/or Raster* objects). If x is a list, additional arguments ... are ignored


integer. which bands (layers) of the file should be used (default is all layers)


integer (or character with layer names) indicating which layers of a RasterBrick should be used (default is all layers)


logical. If TRUE native drivers are used instead of gdal drivers (where available, such as for BIL and Arc-ASCII files)


logical. If TRUE a raster attribute table is created for files that have one


logical. If TRUE the extent and resolution of the objects are not compared. This speeds up the creation of the RasteStack but should be use with great caution. Only use this option when you are absolutely sure that all the data in all the files are aligned, and you need to create RasterStack for many (>100) files


character. To select the variable of interest in a NetCDF file (see raster)


additional filenames or Raster* objects




# file with one layer
fn <- system.file("external/test.grd", package="raster")
s <- stack(fn, fn)
r <- raster(fn)
s <- stack(r, fn) 
#> [1] 2

# file with three layers
slogo <- stack(system.file("external/rlogo.grd", package="raster")) 
#> [1] 3
#> class      : RasterStack 
#> dimensions : 77, 101, 7777, 3  (nrow, ncol, ncell, nlayers)
#> resolution : 1, 1  (x, y)
#> extent     : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
#> crs        : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
#> names      : red, green, blue 
#> min values :   0,     0,    0 
#> max values : 255,   255,  255