Is there any possible way to list files from different locations?
1
0
Entering edit mode
10.0 years ago
Parham ★ 1.6k

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 • 5.7k views
ADD COMMENT
1
Entering edit mode

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).

ADD REPLY
3
Entering edit mode
10.0 years ago
Laurent ★ 1.7k

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)
ADD COMMENT
0
Entering edit mode

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

> fls
character(0)
ADD REPLY
2
Entering edit mode

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)
ADD REPLY
0
Entering edit mode

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!

ADD REPLY

Login before adding your answer.

Traffic: 868 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6