Message-ID: <giolev$sra$1@ger.gmane.org>
Date: 2008-12-22T18:14:45Z
From: Earl F. Glynn
Subject: Globbing Files in R
In-Reply-To: <73f827b50812210735w3956efe5l5cb0dfe35acc0e27@mail.gmail.com>
Gundala Viswanath wrote:
> Typically Perl's idiom would be:
>
> __BEGIN__
> @files = glob("/mydir/*.txt");
>
> foreach my $file (@files) {
> # process the file
> }
> __END__
Something like this has been suggested in R-help before:
files <- dir()
results <- lapply(files, yourprocessing())
The dir function has path and pattern arguments to select the set of
files you want.
This works fine when there are no problems, but often I'll use a for
loop so problem files can be dealt with differently when necessary.
Perhaps something like this:
ProcessList <- dir(pattern="InPerson*")
for (i in 1:length(ProcessList))
{
filename <- ProcessList[i]
. . .
}
efg
Earl F Glynn
Overland Park, KS