Question: Is there any possible way to list files from different locations?
0
gravatar for Parham
5.1 years ago by
Parham1.4k
Sweden
Parham1.4k wrote:

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 • 1.7k views
ADD COMMENTlink modified 5.1 years ago by David W4.7k • written 5.1 years ago by Parham1.4k
1

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 REPLYlink written 5.1 years ago by Ben2.0k
3
gravatar for Laurent
5.1 years ago by
Laurent1.6k
Cambridge, UK
Laurent1.6k wrote:

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 COMMENTlink written 5.1 years ago by Laurent1.6k

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

> fls
character(0)

 

ADD REPLYlink written 5.1 years ago by Parham1.4k
1

I did not look at you code carefully - you provide files in list.file, 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 REPLYlink written 5.1 years ago by Laurent1.6k

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 REPLYlink written 5.1 years ago by Parham1.4k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1344 users visited in the last hour