[Rd] list.files(recursive=T) does not return directory names
bill@insightful.com
bill at insightful.com
Sat Nov 26 01:46:58 CET 2005
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.
a) Is this behavior intended?
b) Is there an easy way to get the names of all directories
under a given one?
b) 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."
More information about the R-devel
mailing list