Hello,

The example code I supplied also runs in less than a minute on my computer
Windows 7, 64-bit R 2.14.0 My actual mask raster is much larger and at a
finer resolution then the one in my example. My raster:

dimensions  : 1800, 4320, 7776000  (nrow, ncol, ncell)
resolution  : 0.08333334, 0.08333334  (x, y)
extent      : -180, 180, -60, 90.00001  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs

On rerunning my code I realized it does not fail with the extract function
but when running:

 >z2<-as.data.frame(do.call(rbind,z))

Error: cannot allocate vector of size 790.5 Mb
In addition: Warning messages:
1: In as.vector(x[, i]) :
  Reached total allocation of 8072Mb: see help(memory.size)
2: In as.vector(x[, i]) :
  Reached total allocation of 8072Mb: see help(memory.size)
3: In as.vector(x[, i]) :
  Reached total allocation of 8072Mb: see help(memory.size)
4: In as.vector(x[, i]) :
  Reached total allocation of 8072Mb: see help(memory.size)

 I am sorry for my confusion on where the error occurred. Let me revise my
question:

***Before I convert the list to a dataframe is it possible to remove the NA
data and duplicate cell numbers?

I would also love to know if there is a better way complete this task.

Thanks,
Daisy






On Tue, Apr 3, 2012 at 4:40 PM, Michael Sumner <mdsumner@gmail.com> wrote:

> What is the actual error when R "runs out of memory"?
>
> This works with no problems for me (Windows 7, 64-bit R 2.15.0), it
> runs in less than a minute, and watching the R process in Task Manager
> it never takes up more than about 150Mb.
>
> How much memory does your machine have? If it's 64-bit you ought to
> have at least 4Gb, and if you have less that might be the problem.
> Otherwise, perhaps you have other memory hungry programs running at
> the same time?
>
> Cheers, Mike.
>
> On Tue, Apr 3, 2012 at 3:56 PM, Daisy Englert Duursma
> <daisy.duursma@gmail.com> wrote:
> > Hi,
> >
> > I am trying to create an xy table of the center of random cells in a
> raster
> > mask. These cells must occur within a certain distance from xy
> locations. I
> > have successfully found 2 ways of doing this, but both run out of memory
> (R
> > 64-bit version 2.14.0) when using very large datasets. I think I have
> gone
> > about this in a backwards manner and assume there is a simpler way to do
> > this.
> >
> > The following example works, but when I use my actual datasets and create
> > lots of overlapping buffers the code runs out of memory. when using the
> > function extract.
> >
> > Thanks,
> > Daisy
> >
> > rm(list = ls())
> >
> > #load libraries
> >
> > library(dismo)
> > library(raster)
> >
> > ##example data
> > #load map of land
> >
> files<-list.files(path=paste(system.file(package="dismo"),"/ex",sep=""),pattern="grd",full.names=TRUE)
> > mask <- raster(files[[9]])
> > #make species data
> > pts<-randomPoints(mask,2000)
> >  #extract the unique cell numbers within a 800km buffer of the points,
> > remove NA cells
> > #####momory problems#####
> > z <- extract(mask, pts, buffer=800000,cellnumbers=T)
> > z2<-as.data.frame(do.call(rbind,z))
> > z3<-subset(z2, vals == 1, select = cells)
> > #find the unique cells
> > z4<-unique(z3[,1])
> > #get 1000 random cells from the remaining data
> > cells<-sample(z4, 1000, replace=FALSE)
> > #find lat and long of center point of cells
> > xy_locs<-xyFromCell(mask,cells)
> >
> >
> > --
> > Daisy Englert Duursma
> > Department of Biological Sciences
> > Room E8C156
> > Macquarie University, North Ryde, NSW 2109
> > Australia
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner@gmail.com
>



-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 9256

	[[alternative HTML version deleted]]

