Skip to content

regular expressions in R

4 messages · Alaios, Sarah Goslee, R. Michael Weylandt +1 more

#
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:
[1] "a.txt" "b.txt"
[1] "c.doc"
[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:

  
    
#
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:
#
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: