r <- raster(ncols=36, nrows=18)
r <- init(r, fun=runif)
# there are different ways to set all values to 1
# with a function (this will work for very large files if a file name is supplied)
set1function <- function(x){rep(1, x)}
r <- init(r, fun=set1function, filename='test.grd', overwrite=TRUE)
# easier to do "manually"
r <- setValues(r, rep(1, ncell(r)))
# or
r[] <- rep(1, ncell(r))
Run the code above in your browser using DataLab