Josh,

Thanks for reporting this, I will make 'crop' more conservative. The
easiest way to deal with this (I believe rare) problem is to change the
default setting of "maxmemory":

rasterOptions(maxmemory=1e+07)

After that,

crop(r, E, filename="smallerRast")

will likely run without a problem (although I cannot know for sure).

Robert

On Mon, Mar 4, 2013 at 12:35 PM, Josh O'Brien <joshmobrien@gmail.com> wrote:

> Hi all,
>
> The raster package function crop() can fail for certain sufficiently
> large cropping extents (in terms of number of rows and columns needing
> to be extracted).
>
> The raster I'd like to crop is stored on the disk (i.e. fromDisk(r)
> --> TRUE) and I'm writing the results to a file: the problem seems to
> be that the 'canProcessFromMemory' test in the crop() function is not
> conservative enough.  (To see the statement I'm referring to, do
> 'getMethod("crop", signature="Raster") and look for the if/then block
> beginning "if (canProcessInMemory(out, 3)) {"
>
> Here is an example that's reproducible on my 32-bit Windows XP
> machine, running the current R-devel and raster package version
> 2.0.41. Do be aware that the first step -- creating a large example
> raster -- may take several (up to 10?) minutes:
>
> ###############################################
>
> ## (1) In one R session create a large raster and save it to disk
> library(raster)
> r <- raster(ncol=4502, nrow=5738)
> r[] <- 1:length(r)
> writeRaster(r, filename="bigRast")
>
> ## (2) Then, from another clean R session in the same directory
> library(raster)
> r <- raster("bigRast")
> E <- extent(c(-179, 179, -89, 89))
> crop(r, E, filename="smallerRast")
> ## Error: cannot allocate vector of size 193.8 Mb
>
> ###############################################
>
> My temporary fix has been to use trace() to edit crop's "Raster"
> method so that it writes in blocks whenever canProcessInMemory(out,
> 10) is FALSE. That's obviously overkill, but it does work.
>
> Unless I'm missing something, this is basically a bug report, though
> I'd be happy to learn of any other better workarounds.
>
> Cheers,
>
> Josh
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

