Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient list.files

Tags:

r

system

I want to do the equivalent of ls in R. Say I want ls /a/b/c/201*/*/d/e/f/*/sameNameFile.gz, this command take 5 seconds to run on a terminal, I tried to use list.files but it takes a path argument and need recursive=TRUE. It is taking ages...

Is there a function I could use (or an option to list.files) that would allow me to run this ls command (I know I can run the comamnd itself with system(cmd,intern=TRUE) but I want a R solution)

like image 620
statquant Avatar asked Feb 14 '14 13:02

statquant


1 Answers

The result from the related question

Fast test if directory is empty

was that on some systems, system("ls -f -R", intern = TRUE) is faster than list.files. Your performance may vary.

The -R switch means recursive; the -f switch means don't sort alphabetically, which is where the performance gain comes from.

like image 102
Richie Cotton Avatar answered Nov 01 '22 08:11

Richie Cotton