[Rd] file.exists does not like path names ending in /

Henrik Bengtsson hb at biostat.ucsf.edu
Fri Jan 17 21:39:24 CET 2014

1. This is one of the reasons for isFile() and isDirectory() in
R.utils.  I add "workarounds" as new ones are discovered.

2. This works (and also tests for existence of a *directory*):

> file_test("-d", "C:/Program Files")
[1] TRUE
> file_test("-d", "C:/Program Files/")
[1] TRUE

3a. "C:" and "C:/" (at the root) are rather special border cases and
they should mean difference things (just as they do at the Windows
command prompt), e.g.

> setwd("C:/Program Files/")
> getwd()
[1] "C:/Program Files"
> setwd("T:/tmp/")
> getwd()
[1] "T:/tmp"
> setwd("C:")
> getwd()
[1] "C:/Program Files"
> setwd("T:")
> getwd()
[1] "T:/tmp"

(A feature rarely used, but correct.)

3b. Contrary to OP's example, file.exists() works correctly on both
these cases (at least back to R 2.15.3), e.g.

> file.exists("C:")
> file.exists("C:/")
[1] TRUE

3c. Related: An inconsistency in file.info("C:/") with workaround
file.info("C:/.") was fixed as of R 3.0.2, cf.


On Fri, Jan 17, 2014 at 11:01 AM, Kirill Müller
<kirill.mueller at ivt.baug.ethz.ch> wrote:
> On 01/17/2014 07:35 PM, William Dunlap wrote:
>>> I think that ignoring a terminal slash/backslash on Windows would do no
>>> >harm:
>> Windows makes a distinction between "C:" and "C:/": the former is
>> not a file (or directory) and the latter is.
> But, according to the documentation, neither would be currently detected by
> file.exists, while the latter is a directory, as you said, and should be
> detected as such.
> -Kirill
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list