Message-ID: <CAP01uRm1zdj0pQsE-mZ2qRJ-OTX-tCrJnyqNLqKV_uu=PqWrYw@mail.gmail.com>
Date: 2012-10-14T09:41:01Z
From: Gabor Grothendieck
Subject: listing the files in a directory using regular expressions
In-Reply-To: <1350198789589-4646119.post@n4.nabble.com>
On Sun, Oct 14, 2012 at 3:13 AM, siddu479 <onlyfordigitalstuff at gmail.com> wrote:
> Hi Experts,
>
> This might be silly question that I am asking, but no way as I am new to
> R.
> I want to list the files in a directory using regular expression like
> A_B*_C*.csv etc.
> How to make this possible in R ?
> I tried like this list.files(dir=".", pattern="A_B*_C*.csv") but this gives
> no output, whereas list.files(.... pattern="*.csv") giving all the .csv
> files in the output, which I do not want.
>
1. Always read the help file:
?list.files
The argument name is path=, not dir=.
2. Also note that the pattern must be specified as a regular
expression and not a glob (as would be specified in a command line
shell). For example, the B* part of the expression in your post means
0 or more B's. It does not mean B followed by anything else.
If you want to use globs rather than regular expressions see
?glob2rx
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com