Question

I don't know if what I try to do is possible! I have a matrix of values (Var_sim) and I convert it as an ff object. The name of this object is created with "paste". Now I want to use this object in the function ffload, this is my code:

Variables[k] = TEMP
Cell_number[i] = 4095
selected_domains = 1

assign(paste("Mat_",Variables[k],"_",Cell_number[i],"_",selected_domains[j],sep=""),as.ff(Var_sim))

Here I have the variable Mat_TEMP_4085_1 as an ff object. I am using that in a loop so I will have various ff objects with various names (different cell_number).I need to use Mat_TEMP_4085_1 (and the others) in a function but I can't just write the name:

ffsave(as.name(paste("Mat_",Variables[k],"_",Cell_number[i],"_",selected_domains[j],sep="")), file="Test")

I have the following error:

Error in ffsave(as.name(paste("Mat_", Variables[k], "_", Cell_number[i],  : 
objet ‘as.name(paste("Mat_", Variables[k], "_", Cell_number[i], "_",     selected_domains[j], sep = ""))’ not found

It doesn't recognize the variable. How can I do?

Was it helpful?

Solution

Does not look like you are using as.name right. Simply remove it or wrap as.character around it, if you wanted to get the variable value from the string name of the variable use get; @Spacedman is right you should prefer lists of names if you can.

tt = "rbind"
print(do.call(tt,list(LETTERS))) # works
print(do.call(as.name(tt),list(LETTERS))) # does not work
print(do.call(as.character(as.name(tt)),list(LETTERS))) # works
print(do.call(get("tt"),list(LETTERS))) # works
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top