0

I want to read large arrays from .mat files into dynamically named ff files in R.

I tried the following:

for(i in 1:numFiles){
    varName = paste0("ffInter",i) # name of the new ff variable
    temp = readMat(Files[i]) #reads the array from .mat file
    assign(varName, ff(vmode = "short", dim = dim(temp)) #preallocate new ff variable
    assign(varName, temp) #assign the values to the ff variable
}                                                            

Problem: After the first "assign" everything is fine. But after the second "assign" the type of the variable "varName" changes to an ordinary array. With static variables you would do the assignment of values like this:

staticVarName[,] = temp

But how can I translate this to an dynamic statement? How can I take care of the "[,]", which are needed according to the ff package documentation?

Cheers and thanks in advance, tholor

tholor
  • 55
  • 1
  • 6
  • I don't know anything about the *ff* package, but in the second assign you just assign the name *varName* to *temp*. What you want to do is to first make the changes you want to the temp variable, then assign *varName* to it. (as.ff in the ff package should be able to cast your array to the type you want). – Jonathan Lisic Oct 14 '14 at 06:17
  • I got a solution for the initial assignment: `assign(varName, ff(initdata = temp, vmode = "short", dim = dim(temp))` works fine. Nevertheless: I still don't know how to assign/change values later on with the dynamic variable name. Any ideas? – tholor Oct 14 '14 at 07:27
  • Thanks, Jonathan (I just saw your comment). That's completely the point. as.ff converts the array to an ff file, but unfortunately to a bigger 1:1 "cloned" file without compression. So it's not really an option. – tholor Oct 14 '14 at 07:35
  • maybe it's not what you are looking for, but you could try an sapply or lapply to as.ff to do a unit by unit conversion. But I'm not sure if a list of ff objects is an ff object list. – Jonathan Lisic Oct 14 '14 at 07:44

0 Answers0