Reputation: 107
I'm writing a function in R that will take the path name of a folder as its argument and return a vector containing the names of all the files in that folder which have the extension ".pvalues".
myFunction <- function(path) {
# return vector that contains the names of all files
# in this folder that end in extension ".pvalues"
}
I know how to get the names of the files in the folder, like so:
> list.files("/Users/me/myfolder/")
[1] "myfile.txt"
[2] "myfile.txt.a"
[3] "myfile.txt.b"
[4] "myfile.txt.a.pvalues"
[5] "myfile.txt.b.pvalues"
Is there an easy way to identify all the files in this folder that end in ".pvalues"? I cannot assume that the names will start with "myfile". They could start with "yourfile", for instance.
Upvotes: 1
Views: 126
Reputation: 43245
take a look at ?list.files
. You want the pattern
argument. list.files(path='/Users/me/myfolder', pattern='*\\.pvalues$')
Upvotes: 5