[R] list.files changed in 2.7.0

Henrik Bengtsson hb at stat.berkeley.edu
Sat Jan 24 03:36:14 CET 2009


And I'm not sure that list.files("C:", full.names=TRUE) returns
correct pathnames, because it lists the files in the current directory
(of C:), not the root of C:. There is a difference between C: and C:/,
and you should get:

list.files("C:", full.names=TRUE)
[1] "C:aFile.txt"
[2] "C:anotherFile.txt"

list.files("C:/", full.names=TRUE)
[1] "C:/Documents and Settings"
[2] "C:/Program Files"

Now we get:

list.files("C:", full.names=TRUE)
[1] "C:/aFile.txt"
[2] "C:/anotherFile.txt"

list.files("C:/", full.names=TRUE)
[1] "C://Documents and Settings"
[2] "C://Program Files"

This causes

pathnames <- list.files("C:", full.names=TRUE);
file.exists(pathnames);

to return all FALSE (not expected), whereas,

pathnames <- list.files("C:");
file.exists(pathnames);

returns all TRUE (expected).

So, that extract slash seems to be the cause.

My $.02

/Henrik

On Fri, Jan 23, 2009 at 2:42 PM,  <davidr at rhotrading.com> wrote:
> I just noticed a change in the behavior of list.files from 2.6.1pat to
> 2.7.0
> (I noticed it in 2.8.1 and traced back.)
>
> Previously, if the directory ended with a slash, and full.names=TRUE,
> the names
> returned had a single slash at the end of the directory,
> but now there are two. I noticed since I was getting a list of certain
> files and
> then grepping in the list for a full name formed with a single slash.
> (The double slash would be OK if I were opening the file since the OS
> treats double
> slash in a path the same as a single slash.)
>
> I searched through the release notes, etc., and couldn't find this
> announced.
>
> Try
>> list.files("C:", full.names=TRUE)
>> list.files("C:/", full.names=TRUE)
>
> Is there any chance that this could be put back to the single slash
> behavior?
>
> (This was on Windows XP.)
>
> Thanks,
> David L. Reiner
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list