Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R list files with multiple conditions

I want to list all files in a directory that met certain conditions (date and currency). So with only one condition the argument pattern in list.files works well:

    file.ls <- list.files(path='~/DATA/PiP/Curvas/',pattern='20130801')

For multiple conditions I've tried:

    file.ls <- list.files(path='~/DATA/PiP/Curvas/',pattern=c('20130801','USD'))

But had the same result as the first one. Is there a way to have multiple criteria in pattern argument of list.files?

like image 639
capm Avatar asked Aug 03 '13 01:08

capm


3 Answers

file.ls <- list.files(path='~/DATA/PiP/Curvas/',pattern="20130801|USD")
like image 190
Metrics Avatar answered Nov 08 '22 03:11

Metrics


In line with Baptiste and the answer on this post (list.files pattern argument in R, extended regular expression use), you can use the following expression:

file.ls <- list.files(path='~/DATA/PiP/Curvas/',
pattern=glob2rx("*20130801*USD*"))

Where * is the wildcard.

like image 39
Dendrobates Avatar answered Nov 08 '22 02:11

Dendrobates


Here it is:

file.ls2 = intersect(list.files(pattern = "20130801"), list.files(pattern = "USD"))
like image 10
Karabirupa Dutta Avatar answered Nov 08 '22 03:11

Karabirupa Dutta