siddu479
2012-Oct-14 07:13 UTC
[R] listing the files in a directory using regular expressions
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. Thanks Sidda -- View this message in context: http://r.789695.n4.nabble.com/listing-the-files-in-a-directory-using-regular-expressions-tp4646119.html Sent from the R help mailing list archive at Nabble.com.
Rui Barradas
2012-Oct-14 09:36 UTC
[R] listing the files in a directory using regular expressions
Hello, Try the pattern "A_B.*_C.*\\.csv". Hope this helps, Rui Barradas Em 14-10-2012 08:13, siddu479 escreveu:> 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. > > Thanks > Sidda > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/listing-the-files-in-a-directory-using-regular-expressions-tp4646119.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
Gabor Grothendieck
2012-Oct-14 09:41 UTC
[R] listing the files in a directory using regular expressions
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
siddu479
2012-Oct-14 12:03 UTC
[R] listing the files in a directory using regular expressions
Hi Gabor, Thanks for your reply.. *glob2rx()* function works for my requirement to address global pattern(using *) of files like we use in Unix shell. Sidda -- View this message in context: http://r.789695.n4.nabble.com/listing-the-files-in-a-directory-using-regular-expressions-tp4646119p4646130.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2012-Oct-14 21:56 UTC
[R] listing the files in a directory using regular expressions
On Sun, Oct 14, 2012 at 8:03 AM, siddu479 <onlyfordigitalstuff at gmail.com> wrote:> > Hi Gabor, > > Thanks for your reply.. > *glob2rx()* function works for my requirement to address global > pattern(using *) of files like we use in Unix shell. > > Sidda >Also Sys.glob may be useful here.
Possibly Parallel Threads
- transforming a .csv file column names as per a particular column rows using R code
- Excluding all teh columns from a data frame if the standard deviation of that column is zero(0).
- alloca combining, not (yet) possible ?
- alloca combining, not (yet) possible ?
- Getting error while running unix commands within R using system() function