Hi,
I am trying to list all the sub-directories in a particular directory
and having a few issues. list.dirs seems to be slightly broken and/or
poorly labelled. My issue appears to be the same as this one, from
the archives:
http://tolstoy.newcastle.edu.au/R/e16/help/11/11/1156.html
Here is some of my current platform info:
R version 2.15.0 (2012-03-30)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
RStudio Version 0.95.263
Setting the full.names argument to FALSE simply doesn't appear to
work. To get the desired behavior, I have to wrap the entire command
in basename(), as in the final example. BTW, I've truncated to output
in width and length for the sake of brevity.
> getwd()
[1] "/Users/name/Documents/R"> list.dirs(full.names = FALSE, recursive = FALSE)
[1] "./abc" "./bcd"
"./cde" "./data1"> list.dirs(".", full.names = FALSE, recursive = FALSE)
[1] "./abc" "./bcd"
"./cde" "./data1"> list.dirs("./", full.names = FALSE, recursive = FALSE)
[1] ".//abc" ".//bcd"
".//cde"
".//data1"> list.dirs("data1/SP", full.names = FALSE, recursive = FALSE)
[1] "data1/SP/2010-01-29" "data1/SP/2010-12-13"
"data1/SP/2010-12-31"
[7] "data1/SP/2011-01-06" "data1/SP/2011-01-07"
"data1/SP/2011-01-10"
[13] "data1/SP/2011-01-14" "data1/SP/2011-01-18"
"data1/SP/2011-01-19"
[19] "data1/SP/2011-01-25" "data1/SP/2011-01-26"
"data1/SP/2011-01-27"> list.dirs("data/SP", full.names = TRUE, recursive = FALSE)
[1] "data1/SP/2010-01-29" "data1/SP/2010-12-13"
"data1/SP/2010-12-31"
[7] "data1/SP/2011-01-06" "data1/SP/2011-01-07"
"data1/SP/2011-01-10"
[13] "data1/SP/2011-01-14" "data1/SP/2011-01-18"
"data1/SP/2011-01-19"
[19] "data1/SP/2011-01-25" "data1/SP/2011-01-26"
"data1/SP/2011-01-27"> basename(list.dirs("data1/SP", full.names = FALSE, recursive =
FALSE))
[1] "2010-01-29" "2010-12-13" "2010-12-31"
"2011-01-03" "2011-01-04"
[11] "2011-01-12" "2011-01-13" "2011-01-14"
"2011-01-18" "2011-01-19"
[21] "2011-01-27" "2011-01-28" "2011-01-31"
"2011-02-01" "2011-02-02"
[31] "2011-02-10" "2011-02-11" "2011-02-14"
"2011-02-15" "2011-02-16"
Is the full.names argument broken, and what is it supposed to do?
Even as it currently is, I wouldn't exactly describe the outputted
pathnames as "full", more accurately as "relative pathnames"
from the
current working directory.
Does anyone know if list.dirs is really broken or if this is the
desired behavior?
Thanks,
James