[R] *** saving files ***

Wiener, Matthew matthew_wiener at merck.com
Wed Sep 14 16:10:36 CEST 2005


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 at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Shahrokh Keiwani
Sent: Wednesday, September 14, 2005 9:43 AM
To: r-help at 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 at 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




More information about the R-help mailing list