[R] A very big matrix inside a function
Francisco Fabuel
fabuel_fra at gva.es
Tue Sep 27 10:54:39 CEST 2011
Dear listers:
As a part of a intermediate process, I need to use and modify a very big
matrix (some 30000x30000) inside the body of a function. If the matrix is
defined in the function, R shows a error message "Cannot allocate vector of
size 6.7 Gb". But if I define the matrix before the function is called (as
soon as the dimension can be calculated) R can allocate it. The problem is
that although my function can use the matrix, cannot modify it. The schema
is the following:
# OPTION 1
# Function definition
Myfunction<-function(parameters, ...) {
...
Verybigmatrix<-matrix(0, n, n) # Matrix definition inside the function
...
}
# Main process
...
Value.returned<-Myfunction(parameters, ...) # R issues an error message "
Cannot allocate vector of size 6.7 Gb"
...
# OPTION 2
# Function definition...
Myfunction<-function(parameters, ...) {
...
Verybigmatrix[index1, index2]<<-newvalue # Issues an error message " Cannot
allocate vector of size 6.7 Gb"
# It assignation is made with `<-` error is issued too
...
}
# Main process
...
Verybigmatrix<-matrix(0, n, n) # Definition before Myfunction is called
doesn't issue an error
...
Value.returned<-Myfunction(parameters, ...) # R sees Verybigmatrix but if I
try to modify it issues an error message " Cannot allocate vector of size
6.7 Gb"
...
Characteristics of the machine I'm working on:
Operating system: Redhat Enterprise Linux 6
Kernel and CPU: Linux 2.6.32-131.6.1.el6.x86_64 on x86_64
Processor information: Intel(R) Xeon(TM) CPU 3.60GHz, 4 cores
Memory: 8 GB
Thanks in advance for your help.
Francisco
More information about the R-help
mailing list