I cannot find any example on how to use the pattern=
parameter in list.files
for more complex operations.
I would like to get all the files that include either 'XM' or 'EM' and are of the .cvs type
Can someone please help me.
I was trying something like
list.files(path='.', pattern="[XM | EM] & csv")
but it is definitely wrong
In other words, square brackets match exactly one character. (a-z0-9) will match two characters, the first is one of abcdefghijklmnopqrstuvwxyz , the second is one of 0123456789 , just as if the parenthesis weren't there. The () will allow you to read exactly which characters were matched.
$ means "Match the end of the string" (the position after the last character in the string).
To create that regular expression, you need to use a string, which also needs to escape \ . That means to match a literal \ you need to write "\\\\" — you need four backslashes to match one! In this book, I'll write regular expression as \. and strings that represent the regular expression as "\\." .
Two types of regular expressions are used in R, extended regular expressions (the default) and Perl-like regular expressions used by perl = TRUE . There is also fixed = TRUE which can be considered to use a literal regular expression.
try this:
list.files(path='.', pattern="(XM|EM).*\\.csv$")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With