[R] Running R Script on a Sequence of Files

Gustavo Carvalho gustavo.bio+R at gmail.com
Sun Dec 7 04:36:39 CET 2008


Thanks a lot!

On Fri, Dec 5, 2008 at 5:54 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> Try this:
>
> dir()[!file.info(dir())$isdir]
>
>
> On Fri, Dec 5, 2008 at 2:30 PM, Gustavo Carvalho
> <gustavo.bio+R at gmail.com> wrote:
>> Is there a way to list only the files in a given directory without
>> passing pattern="..." to list.files()?
>>
>> On Fri, Dec 5, 2008 at 5:10 PM, Kyle. <ambertk at gmail.com> wrote:
>>> Thanks, Barry. I'll use that in the future.
>>>
>>>
>>> ---Kyle.
>>>
>>> On Fri, Dec 5, 2008 at 11:01 AM, Barry Rowlingson <
>>> b.rowlingson at lancaster.ac.uk> wrote:
>>>
>>>> 2008/12/5 Chris Poliquin <poliquin at sas.upenn.edu>:
>>>> > 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?
>>>>
>>>>  I can't believe the two 'solutions' already posted. It's easy:
>>>>
>>>>  ?list.files
>>>>
>>>> Barry
>>>>
>>>> ______________________________________________
>>>> 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.
>>>>
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>> ______________________________________________
>> 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