0

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?

Douie
  • 201
  • 4
  • 11
  • What's all this 'ff' stuff? From a package? Also, making names and using assign is nearly always wrong, and is likely the cause of your problem. Make _lists_ of things rather than trying to put indexes into names of things. – Spacedman Jan 16 '14 at 10:28
  • Yes ff is a package and I use it because I am working with large data. The function will write each ff file in a folder and after that I can reload them and use one matrix by one. The problem is when I load an ff object, the variable name is the name of the object saved in ffsave. If I put always the same name and I want to load several ff objets, the variable will be overwrited because it will be the same name. – Douie Jan 16 '14 at 10:41
  • You can use the `envir` argument to load each one into a different environment and make a list out of those. – Spacedman Jan 16 '14 at 13:30

1 Answers1

0

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
crogg01
  • 2,446
  • 15
  • 35
  • Thanks for your answer. Whatever I try I still have the same error (get, as.character(as.name()) or juste paste()). When I just print the code it gives me the name I want but when I need to use it in the function it doesn't recognize it – Douie Jan 16 '14 at 12:24
  • I looked at ffsave, looks like you need to specify a list of names: `require(ff); n <- 8e3; assign( paste(LETTERS[1:3],collapse=""), ff(sample(n, n, TRUE), vmode="integer", length=n, filename="~/test/ABC.ff") );ffsave(list=paste(LETTERS[1:3],collapse=""),file="~/test/another_ABC")` – crogg01 Jan 16 '14 at 12:37
  • Thanks, it works! I needed "list". The names are set by the arguments the user put in the function. I can have almost 500 000 names from different parameters combinations - I think is more complicated to use a list of names – Douie Jan 16 '14 at 13:09