[R] Running R Script on a Sequence of Files

Steve_Friedman at nps.gov Steve_Friedman at nps.gov
Fri Dec 5 21:12:18 CET 2008


It seems that you have 900 files with the same parameters in each file (I
might be reading more between the lines here than you inferred). However if
this is the case, why not import each of the files into a common database
and then link the database using ODBC connectivity options.  If that is
practical, you could then code a series of subsetting options to select the
data you need for specific analysis, write reports, and then iteratively
select the next set of records.

I may be suggesting a very simple solution, so forgive me if this
trivializes your problem too greatly.

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

Steve_Friedman at nps.gov
Office (305) 224 - 4282
Fax     (305) 224 - 4147


                                                                           
             Chris Poliquin                                                
             <poliquin at sas.upe                                             
             nn.edu>                                                    To 
             Sent by:                  r-help at r-project.org                
             r-help-bounces at r-                                          cc 
             project.org                                                   
                                                                   Subject 
                                       [R] Running R Script on a Sequence  
             12/05/2008 01:01          of Files                            
             PM EST                                                        
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi,

I have about 900 files that I need to run the same R script on.  I
looked over the R Data Import/Export Manual and  couldn't come up with
a way to read in a sequence of files.

The files all have unique names and are in the same directory.  What I
want to do is:
1) Create a list of the file names in the directory (this is really
what I need help with)
2) For each item in the list...
             a) open the file with read.table
             b) perform some analysis
             c) append some results to an array or save them to another
file
3) Next File

My initial instinct is to use Python to rename all the files with
numbers 1:900 and then read them all, but the file names contain some
information that I would like to keep intact and having to keep a
separate database of original names and numbers seems inefficient.  Is
there a way to have R read all the files in a directory one at a time?

- Chris

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list