[R] Regular expressions on filenames
smartpink111 at yahoo.com
Thu Jan 16 01:48:02 CET 2014
FILELIST <- list.files()
# "FILE.csv" "FILE.XXX.csv" "FILE.YYY.xls"
sub("(.*)\\..*$", "\\1", basename(FILELIST))
# "FILE" "FILE.XXX" "FILE.YYY"
On Wednesday, January 15, 2014 7:35 PM, Fisher Dennis <fisher at plessthan.com> wrote:
I am writing code to read a large number of files in a particular folder. In some situations, there may be two versions of the file with different extensions, e.g.:
I extracted the portion before the extension with:
sub("\\..*$", "", basename(FILELIST))
to find duplicates. All was well until I encountered files named:
My regular expression extracted only the “FILE” portion of the text and claimed that the filenames (without the extensions) matched. Can someone provide me with the appropriate regular expression to deal with this? Thanks.
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-866-PLessThan (1-866-753-7784)
R-help at r-project.org mailing list
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