pedrosaurio
pedrosaurio

Reputation: 4936

How to do complex regular expressions in list.files in R

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

Upvotes: 25

Views: 14402

Answers (1)

Tom
Tom

Reputation: 3063

try this:

list.files(path='.', pattern="(XM|EM).*\\.csv$")

Upvotes: 31

Related Questions