Pascal,

I see that names are written to file if (1) the cell values are in memory
(not, as in your case on file) or (2) if you write a RasterBrick (not as in
your case a RasterLayer). Bug fixed in next version.

Work-arounds:
1) write a RasterBrick instead of a RasterLayer

names(x) <- 'zebra'
x <- brick(x)
writeRaster(x, 'file.grd')

or try to load values into memory before using writeRaster (e.g.
names(x) <- 'giraffe'
x <- readAll(x) )
writeRaster(x, 'file.grd')

Thanks for reporting this,
Robert

On Fri, Oct 26, 2012 at 7:19 AM, Pascal Title <ptitle@umich.edu> wrote:

> Hi all,
>
> I'm working with a set of rasters in R, and writing them to disk. However,
> when I read them back in, the layer name is back to default. How can I
> define the layer name and have that carry over to the raster that is saved
> to disk?
>
> I'm using R 2.15.1, raster package 2.0-12, Mac OSX Mountain Lion. Here I
> show the raster object, I then define the name, and then I write it to
> disk. You can see that the layer name switches back to "layer".
>
> > comb
> class       : RasterLayer
> dimensions  : 7200, 7200, 51840000  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : -150, -90, 30, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source :
>
> /private/var/folders/4t/f1r24pf90d724kpr9m7bpl640000gp/T/R_raster_tmp/Pascal/raster_tmp_2012-10-26_101222_71239.grd
>
> names       : layer
> values      : -290, 239  (min, max)
>
> > names(comb)<-'bio1'
> > comb
> class       : RasterLayer
> dimensions  : 7200, 7200, 51840000  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : -150, -90, 30, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source :
>
> /private/var/folders/4t/f1r24pf90d724kpr9m7bpl640000gp/T/R_raster_tmp/Pascal/raster_tmp_2012-10-26_101222_71239.grd
>
> names       : bio1
> values      : -290, 239  (min, max)
>
> > writeRaster(comb,filename='/Users/Pascal/Desktop/bio1.grd')
> class       : RasterLayer
> dimensions  : 7200, 7200, 51840000  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : -150, -90, 30, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : /Users/Pascal/Desktop/bio1.grd
> names       : layer
> values      : -290, 239  (min, max)
>
> Any suggestions would be greatly appreciated! Thanks!
>
> -Pascal
>
>
> --
> Pascal Title, MSc.
> PhD student, Rabosky Lab <http://cteg.berkeley.edu/~rabosky/Home.html>
> Dept of Ecology and Evolutionary Biology
> University of Michigan
> ptitle@umich.edu
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

