This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is there any possible way to list files from different locations?

In the script I am running there is this line:

fls <- list.files("./tophat_all", pattern="bam$", full.names = T)

Is there any possible way to list files from different directories, like below?

fls <- list.files("D:/tophat_all/nmtasync_R1noT.bam", "D:/allfiles/tophat_all/wtasync_R1noT.bam", "C:/etc./tophat_all/wtasync_R2noT.bam", pattern="bam$", full.names = T)

My life will be way easier if I can do that!

list.files r

c() around paths? ?list.files shows the path argument takes a character vector (not entirely clear why you're listing files already specified by their absolute path but ok).

1 answer

Use a vector of dir names as first argument:

fls <- list.files(c("D:/tophat_all/nmtasync_R1noT.bam", 
                    "D:/allfiles/tophat_all/wtasync_R1noT.bam", 
                    "C:/etc./tophat_all/wtasync_R2noT.bam"), 
                  pattern="bam$", full.names = TRUE)

That returns with zero characters in it! Do you know any other way?

> fls
character(0)

I did not look at you code carefully - you provide files in list.files, when directories are expected. The list of files is what the function will return. Try something like

fls <- list.files(c("D:/tophat_all/", 
                    "D:/allfiles/tophat_all/", 
                    "C:/etc./tophat_all/"), 
                  pattern="bam$", full.names = TRUE)

Thanks! In the beginning the idea was to just list specific files from different directories. But this also helps, I will put them in different folders!!! I am not bioinformatists therefore I have a though life working around with codes!

Log in to answer this question.