[R] rownames cannot allocate vector of size

2010-02-22 Thread Larson, TR

Hi,

On R 2.10.1 for Windows, when I do the following to duplicate the 
structure of a large numeric matrix called matrix1:


matrix2 - matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1))

and then

rownames(matrix2) - rownames(matrix1)

I get a cannot allocate vector of size xxMb error

but if I instead do:

rnames - list()
rnames - rownames(matrix1)
matrix2 - matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1),dimnames=rnames)

I get no error.

Of course both approaches work in R on Unix without memory limits.  But 
I'm intrigued about the apaprent difference in memory usage/allocation 
for the two above approaches. Is there any explanation for this 
difference in behaviour?


thanks
Tony

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] rownames cannot allocate vector of size

2010-02-22 Thread Benilton Carvalho
assigning rownames (after the object is created) triggers a copy of
the object... if you assign the rownames at creation time, no extra
copies...

b

On Mon, Feb 22, 2010 at 9:46 AM, Larson, TR t...@york.ac.uk wrote:
 Hi,

 On R 2.10.1 for Windows, when I do the following to duplicate the structure
 of a large numeric matrix called matrix1:

 matrix2 - matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1))

 and then

 rownames(matrix2) - rownames(matrix1)

 I get a cannot allocate vector of size xxMb error

 but if I instead do:

 rnames - list()
 rnames - rownames(matrix1)
 matrix2 - matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1),dimnames=rnames)

 I get no error.

 Of course both approaches work in R on Unix without memory limits.  But I'm
 intrigued about the apaprent difference in memory usage/allocation for the
 two above approaches. Is there any explanation for this difference in
 behaviour?

 thanks
 Tony

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.