From hb at biostat.ucsf.edu  Fri Jan 17 21:39:24 2014
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Fri, 17 Jan 2014 12:39:24 -0800
Subject: [Rd] file.exists does not like path names ending in /
In-Reply-To: <52D97E08.5050705@ivt.baug.ethz.ch>
References: <CAP01uRmStfL2Kd0AK0KGGkdeUY_Qbde885AfSDy8VNDHbras7g@mail.gmail.com>
	<21209.4385.976759.215210@stat.math.ethz.ch>
	<CAP01uRmv3VmecKQMtyoAQM_yifKXcKtw1D66djbJ459fxtQRGw@mail.gmail.com>
	<52D96795.8040604@ivt.baug.ethz.ch>
	<E66794E69CFDE04D9A70842786030B933FA2242F@PA-MBX01.na.tibco.com>
	<52D97E08.5050705@ivt.baug.ethz.ch>
Message-ID: <CAFDcVCR_zvjPzk3V_-LYdC2W4LA78n-4yFgc58q-nHaoO4JYEQ@mail.gmail.com>

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:")
[1] FALSE
> 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.
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15302

/Henrik


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



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