[Rd] list.files(recursive=T) does not return directory names

From: <bill_at_insightful.com>
Date: Sat 26 Nov 2005 - 00:46:58 GMT


list.files() (and dir()) don't appear to return names of directories when one uses the recursive=T argument. E.g.,
> dir(file.path(R.home(),"library"), pattern="^R$", recursive=T)
  [1] "Malmig/help/R"
but the unix find commmand finds lots of R directories
> z <- system(paste("find", file.path(R.home(),"library"), "-name R"), intern=T)
> length(z)

  [1] 665
> file.info(z[1:3])[,1:3]

                                            size isdir mode
  /dept/devel/sw/R/R.linux/R/library/aCGH/R 4096  TRUE 2755
  /dept/devel/sw/R/R.linux/R/library/RBGL/R 4096 TRUE 2755   /dept/devel/sw/R/R.linux/R/library/XML/R 4096 TRUE 2755

The help file is silent on this behavior. I am writing an emulation of these for functions for Splus and was wondering about 3 things.

  1. Is this behavior intended?
  2. Is there an easy way to get the names of all directories under a given one?
  3. I would like to add an argument to list.files() to specify that I'd like the names of only non-directories, only directories, or both. I've tentatively called this argument "type" (following the unix find command) and the acceptable values are "files", "directories", and "all" (or any abbreviation). Symbolic links, fifos, etc. might be nice, but I don't want to fill the code with unixisms or tempt folks to use them. Would adding type = "files","directories","all" to list.files and dir conflict with any plans for R's list.files or dir?

Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146
 "Formerly known as MathSoft, Insightful Corporation provides analytical  solutions leveraging S-PLUS, StatServer and consulting services."

 "All statements in this message represent the opinions of the author and do  not necessarily reflect Insightful Corporation policy or position."



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Nov 26 11:51:20 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:34 GMT