[R-sig-Geo] help with writing focal operations to new raster file
Robert J. Hijmans
r.hijmans at gmail.com
Mon Jun 21 08:28:46 CEST 2010
Dear Beth,
This one is puzzling:
> Error in .Internal(which(x)) : no internal function "which"
My guess is that something has gone wrong with the installation or
raster or a mismatch with the R version. Could you re-install raster
(from CRAN)? Are you using an older version or R? I recently heard
from two people with similar error messages; they resolved the problem
by in one case by properly installing raster, and by updating R in the
other case. I am guessing here as I cannot reproduce this error. Could
you please send me your sessionInfo()
Apart from that, you could restate your script to something like this:
trial <- raster("data.asc")
focal.trial <- focal(trial, ngb=3, fun=mean, na.rm=TRUE)
If you also want to save the results to file, you can add a filename argument:
focal.trial <- focal(trial, ngb=3, fun=mean, na.rm=TRUE, filename="focal.tif")
In your example you provide the filename "raster.focal" of which
'focal" was interpreted as the filename extension. The extension is
used to guess the file format you want (unless you also provide a
"format= " argument). The function expects a known extension such as
tif, asc, img, rst, .... In this case, it simply warned you that
"focal" could not be associated with a file format.
Robert
On Sun, Jun 20, 2010 at 10:51 PM, Beth Crase <Beth.Crase at nt.gov.au> wrote:
> Dear List,
> I am new to the raster package, but very excited that it can do focal calculations.
>
> I read an Ascii file as a Spatial Grid (using spdep package) and then to a RasterLayer (using raster package) as follows:
> #read ascii file in as a SpatialGrid
> trial<-readAsciiGrid("data.asc")
> #convert SpatialGrid to RasterLayer
> raster.trial <- raster(trial)
> Then I tried to clone RasterLayer so I have somewhere to put the focal values, but I am not sure whether this is correct:
> raster.focal <- raster.trial
> Then I tried to calculate focal values from "raster.trial" and write them to "raster.focal"
> focal(raster.trial, ngb=3, fun=mean, na.rm=TRUE, filename="raster.focal")
>
> Unfortunately I get the following errors:
> Error in .Internal(which(x)) : no internal function "which"
> In addition: Warning message:
> In .getFormat(filename) : extension .focalis unknown. Using default format.
> I am not sure how to interpret the error messages.
> And I am not sure I have the correct approach with cloning the first raster file.
>
> Can someone help?
> Cheers
> Beth.
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list