# NOT RUN {
r <- raster(ncols=36, nrows=18)
x <- init(r, fun='cell')
y <- init(r, fun=runif)
# there are different ways to set all values to 1
# for large rasters:
# set1f <- function(x){rep(1, x)}
# z1 <- init(r, fun=set1f, filename=rasterTmpFile(), overwrite=TRUE)
# This is equivalent to (but not memory safe):
z2 <- setValues(r, rep(1, ncell(r)))
# or
values(r) <- rep(1, ncell(r))
# or
values(r) <- 1
# }
Run the code above in your browser using DataLab