[R] Memory limit problem

David Winsemius dwinsemius at comcast.net
Tue Oct 12 07:07:13 CEST 2010


On Oct 11, 2010, at 11:49 PM, Tim Clark wrote:

> Dear List,
>
> I am trying to plot bathymetry contours around the Hawaiian Islands  
> using the
> package rgdal and PBSmapping.  I have run into a memory limit when  
> trying to
> combine two fairly small objects using cbind().  I have increased  
> the memory to
> 4GB, but am being told I can't allocate a vector of size 240 Kb.  I  
> am running R
> 2.11.1 on a Dell Optiplex 760 with Windows XP.  I have pasted the  
> error message
> and summaries of the objects below.  Thanks for your help.  Tim
>
>
>>      xyz<-cbind(hi.to.utm,z=b.depth$z)
> Error: cannot allocate vector of size 240 Kb

You have too much other "stuff".
Try this:

getsizes <- function() {z <- sapply(ls(envir=globalenv()),
                                 function(x) object.size(get(x)))
                (tmp <- as.matrix(rev(sort(z))[1:10]))}
getsizes()

You will see a list of the largest objects in descending order. Then  
use rm() to clear out unneeded items.

-- 
David,

>
>> memory.limit()
> [1] 4000

Seems unlikely that you really have that much space in that 32 bit OS.


>> memory.size()
> [1] 1971.68
>
>> summary(hi.to.utm)
> Object of class SpatialPoints
> Coordinates:
>         min       max
> x  708745.5  923406.7
> y 2046153.1 2327910.9
> Is projected: TRUE
> proj4string :
> [+proj=utm +zone=4 +datum=NAD83 +ellps=GRS80 +towgs84=0,0,0]
> Number of points: 15328
>
>> str(hi.to.utm)
> Formal class 'SpatialPoints' [package "sp"] with 3 slots
>   ..@ coords     : num [1:15328, 1:2] 708746 710482 712218 713944  
> 715681 ...
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : NULL
>   .. .. ..$ : chr [1:2] "x" "y"
>   ..@ bbox       : num [1:2, 1:2] 708746 2046153 923407 2327911
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : chr [1:2] "x" "y"
>   .. .. ..$ : chr [1:2] "min" "max"
>   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
>   .. .. ..@ projargs: chr " +proj=utm +zone=4 +datum=NAD83  
> +ellps=GRS80
> +towgs84=0,0,0"
>
>
>> summary(b.depth)
>        x                y               z
>  Min.   :-157.0   Min.   :18.50   Min.   :-5783
>  1st Qu.:-156.6   1st Qu.:18.98   1st Qu.:-4565
>  Median :-156.1   Median :19.80   Median :-3358
>  Mean   :-156.1   Mean   :19.73   Mean   :-3012
>  3rd Qu.:-155.5   3rd Qu.:20.41   3rd Qu.:-1601
>  Max.   :-155.0   Max.   :21.00   Max.   :    0
>
>> str(b.depth)
> 'data.frame':   15328 obs. of  3 variables:
>  $ x: num  -157 -157 -157 -157 -157 ...
>  $ y: num  21 21 21 21 21 ...
>  $ z: num  -110 -114 -110 -88 -76 -122 -196 -224 -240 -238 ...
>
>
>
> Tim Clark
> Marine Ecologist
> National Park of American Samoa

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list