An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111221/88852704/attachment.pl>
regular expressions in R
4 messages · Alaios, Sarah Goslee, R. Michael Weylandt +1 more
From the help for dir:
File naming conventions are platform dependent. The pattern
matching works with the case of file names as returned by the OS
On my linux system, this works:
dir(pattern="*.txt")
[1] "a.txt" "b.txt"
dir(pattern="*.doc")
[1] "c.doc"
dir(pattern="*.doc|*.txt")
[1] "a.txt" "b.txt" "c.doc" You don't tell us your OS, so I have no idea whether it will work for you. Sarah
On Wed, Dec 21, 2011 at 11:04 AM, Alaios <alaios at yahoo.com> wrote:
Dear all I would like to ask from dir function in R (?dir) to give me only the files that end with .txt or .doc. The dir functions supports the use of patterns (is not that regular expressions) for doing that. ? print(dir(i,full.names=TRUE,pattern=.....)) Could you please help me compose such a pattern? B.R Alex
Sarah Goslee http://www.functionaldiversity.org
Do you wish to include .docx files as well or just .doc? Michael
On Wed, Dec 21, 2011 at 10:04 AM, Alaios <alaios at yahoo.com> wrote:
Dear all I would like to ask from dir function in R (?dir) to give me only the files that end with .txt or .doc. The dir functions supports the use of patterns (is not that regular expressions) for doing that. ? print(dir(i,full.names=TRUE,pattern=.....)) Could you please help me compose such a pattern? B.R Alex ? ? ? ?[[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.
To be correct for the regular expression, it should be: dir(pattern = "\\.(txt|doc)$") The form dir(pattern="*.txt") will match 'txt' appearing anywhere in the name; this looks like the argument you would have used to "Sys.glob" which is a UNIX style file name match and not a regular expression. "." matches any character unless you escape it to mean a 'period'. On Wed, Dec 21, 2011 at 11:11 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
Do you wish to include .docx files as well or just .doc? Michael On Wed, Dec 21, 2011 at 10:04 AM, Alaios <alaios at yahoo.com> wrote:
Dear all I would like to ask from dir function in R (?dir) to give me only the files that end with .txt or .doc. The dir functions supports the use of patterns (is not that regular expressions) for doing that. ? print(dir(i,full.names=TRUE,pattern=.....)) Could you please help me compose such a pattern? B.R Alex ? ? ? ?[[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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.