[Rd] file.exists does not like path names ending in /
Martin Maechler
maechler at stat.math.ethz.ch
Fri Jan 17 12:16:49 CET 2014
>>>>> Gabor Grothendieck <ggrothendieck at gmail.com>
>>>>> on Fri, 17 Jan 2014 00:10:43 -0500 writes:
> If a path name ends in slash then file.exists says it does
> not exist. I would have expected these to all return
> TRUE.
>> file.exists("/Program Files")
> [1] TRUE
>> file.exists("/Program Files/")
> [1] FALSE
>> file.exists(normalizePath("/Program Files/"))
> [1] FALSE
>> R.version.string
> [1] "R version 3.0.2 Patched (2013-11-25 r64299)"
I would also have expected all these to work,
but that is only because I do not use Windows;
indeed, for me (Linux Fedora 19, but I'm pretty sure *any*
version):
> dir.create("/tmp/foo bar")
> normalizePath("/tmp/foo bar/")
[1] "/tmp/foo bar"
> file.exists("/tmp/foo bar/")
[1] TRUE
> file.exists(normalizePath("/tmp/foo bar/"))
[1] TRUE
>
> I am using Windows 8.1 .
poor you ;-) yes, don't take it personally
Last but not least ?file.exists in its 'Details' section
mentions several times how Windows behaves differently from the
civilized world (:-)
notably that it also says
(However,
directory names must not include a trailing backslash or slash on
Windows.)
So, all seems as documented, but unfortunately your (and most
probably not only yours !!) expectations are different.
I agree that this is quite unfortunate, and we all would be
happy if OSes were consistent here.
I wonder if R couldn't help you (and many others) better to
gloss over these OS differences in a helpful way.
This list may be a good place to discuss such proposals ...
Martin
--
Martin Maechler ETH Zurich -- and R Core Team
More information about the R-devel
mailing list