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

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?



Solution 1:[1]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 akrun