Re: [R] *** saving files ***

From: Wiener, Matthew <matthew_wiener_at_merck.com>
Date: Thu 15 Sep 2005 - 00:10:36 EST


Depending on the size of your objects, you may be able to just keep them in a list, especially as you say you will need them in the same order later.

If because of memory constraints or for some other reason you really need to have a separate file for each round, you can generate object and file names using "paste", assign the object to the name with assign, and save the file:

(warning: untested code)
for(i in 1:n){

	obj.name <- paste(base.obj.name, i, sep = ".")
	file.name <- paste(obj.name, "rda", sep = ".")  # or whatever other
file name you want
	this.obj <- my.fn.that.creates.object(my.arguments)
	assign(obj.name, this.obj)
	save(list = obj.name, file = file.name)
}

When retrieving the files, you can use a similar loop, but instead of using "assign", you can use "get" to retrieve the value and assign it to another variable. Or, in interactive use, you know the name so you can refer to the variable.

Hope this helps,

Matt

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Shahrokh Keiwani Sent: Wednesday, September 14, 2005 9:43 AM To: r-help@stat.math.ethz.ch
Subject: [R] *** saving files ***

   Hi,    

   I need help :o(    

   I want that my function saves result files in a for()-loop while it runs    automatically.    

   the filenames must be saved like:    

   file_1 -> for 1. result

   file_2 -> for 2. result

   file_3 -> for 3. result    

   and

.

.

.
   

   file_n -> for n. result    

   the file names are the same identified by _1, _2 , _3, ... , _n    

   these files will loaded by a second function later in the same sequence    (_1 to _n).    

   how can I do that ...                     

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Sep 21 02:13:30 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 17:12:33 EST