as.character returns a text (R code) representation of a Raster* or Extent object. The main purpose of this is to allow quick generation of objects to use in examples on, for example, stackoverflow.com.

# S4 method for class 'Raster'
as.character(x, ...)
# S4 method for class 'Extent'
as.character(x, ...)

Arguments

x

Raster* or Extent object

...

additional arguments, none implemented

Value

character

Examples

r <- raster(ncol=3, nrow=3)
values(r) <- 1:ncell(r)
as.character(r)
#> [1] "raster(ncols=3, nrows=3, xmn=-180, xmx=180, ymn=-90, ymx=90, crs='+proj=longlat +datum=WGS84 +no_defs')"
s <- stack(r, r)
as.character(s)
#> [1] "brick(ncol=3, nrow=3, nl=2, xmn=-180, xmx=180, ymn=-90, ymx=90, crs='+proj=longlat +datum=WGS84 +no_defs')"
as.character(extent(s))
#> [1] "extent(-180, 180, -90, 90)"

x <- as.character(s)
eval(parse(text=x))
#> class      : RasterBrick 
#> dimensions : 3, 3, 9, 2  (nrow, ncol, ncell, nlayers)
#> resolution : 120, 60  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> 

y <- as.character(extent(s))
eval(parse(text=y))
#> class      : Extent 
#> xmin       : -180 
#> xmax       : 180 
#> ymin       : -90 
#> ymax       : 90