Hi Robert,

thanks for the full report. The suggestion to write a raster file with a 
certain NA values was all I needed. Thinking about it now, other users 
would probably also like to be able to determine the NA-value when 
writing files, so I wouldn't expect a common need.
I will try to stick to the prescribed functions, when changing values.
Thanks again.

cheers,
Brian

On 8/15/2011 8:44 PM, Robert J. Hijmans wrote:
> Brian,
>
> If you simply want to change the NA flag (i.e. the value used used in 
> a _file_ to represent NA), you should use the NAvalue function
>
> NAvalue(rast) <- -9995
>
> But note that this is only to be used when there is an error in the 
> file metadata, or other reason why values that should be NA are not 
> (but are, e.g., -9999, or 0)
>
> You should avoid changing slot values like in your example:
>
> rast@file@nodatavalue <- -9995
>
> Because changing one slot value may have implications for other slot 
> values (that then also need to be changed). I would not recommend 
> directly reading slot values either, but that is certainly less 
> dangerous.
>
>
> > How can I change the default NA value i.e. for a session?
>
> The default value for NA is NA :), but for writing files there is no 
> way to set the default flag value. I could perhaps add that if that is 
> useful, but it is a bit tricky as it depends on the file type 
> (integer, signed or not, real, number of bytes).
>
> You can set the NA flag value when writing with writeRaster and other 
> functions that write files to disk using an argument like "NAflag = 
> -1000"
>
> Robert
>
>
> On Thu, Aug 11, 2011 at 12:16 AM, Brian Oney <zenlines@gmail.com 
> <mailto:zenlines@gmail.com>> wrote:
>
>     Hi All,
>     I guess I have a few questions:
>
>     there are ways to change NA values, such as:
>
>     http://r-sig-geo.2731867.n2.nabble.com/NA-raster-replace-td6348031.html
>
>     When running a few tests on the different methods that do the same
>     thing, I get:
>     # rast is a raster with appr. 1.5e6 cells
>     # when I look at str(rast) I see that I can:
>
>     > system.time(rast@file@nodatavalue <- -9995)
>       user  system elapsed
>          0       0       0
>     # Or this
>     > system.time(rast[is.na <http://is.na>(rast)] <- -9996)
>       user  system elapsed
>       6.55    0.53    7.13
>     # And finally:
>     > system.time(rast <- calc(rast,function(x)ifelse(is.na
>     <http://is.na>(x),-9997,x)))
>       user  system elapsed
>      67.61    0.08   67.83
>
>     Will the 1st referencing method listed also work in the future? Is
>     this recommended?
>     How can I change the default NA value i.e. for a session?
>     I haven't read the do's and don'ts of (R) programming. Where can I
>     do that?
>
>     Cheers,
>     Brian
>
>     _______________________________________________
>     R-sig-Geo mailing list
>     R-sig-Geo@r-project.org <mailto:R-sig-Geo@r-project.org>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>

	[[alternative HTML version deleted]]

