Retrieve list of Files Matching a Pattern Regardless of Case - R

Viewed 30

I am trying to loop through and read some excel files based on a string pattern in the file. I want to read every file containing "feb" in the file name. However, the capitalization of the "Feb" is not always consistent ("FEB", "Feb", "feb", etc.). If I use this code below, it reads all the files with "Feb", but skips the capitalized "FEB" files, or lowercase "feb" files.

files <- list.files(pattern = "Feb")

Is there a way I can tell R to ignore case and just look for the "feb" string?

1 Answers

We can setignore.case to TRUE (by default it is FALSE)

list.files(pattern = "Feb", ignore.case = TRUE)
Related