Skip to content

Possible bug: file.exists() always returns TRUE for prn.us.txt

4 messages · Duncan Murdoch, Joris Meys

#
Dear all,

while preparing some exercises I came across some highly surprising
behaviour of file.exists(). The specific value "prn.us.txt" always returns
TRUE, even though that file is nowhere to be found on my system.

In a fresh R session 3.4.4 installed on Windows 10:
integer(0)
[1] TRUE
[1] FALSE
[1] FALSE
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.4

This also happens in 3.4.3, 3.4.2 and 3.4.1 . It is confirmed by Roman
Lustrik on his system as well :
https://twitter.com/romunov/status/977486929380995072

I suspect this is a bug, or I must be missing something completely.

Cheers
Joris
#
On 24/03/2018 6:16 AM, Joris Meys wrote:
That's a Windows "bug", not an R bug.  Any name starting "prn" (upper or 
lowercase), followed by an extension (i.e. a dot and characters) is 
taken to be the DOS printer device.  According to Writing R Extensions, 
names starting with "?con?, ?prn?, ?aux?, ?clock$?, ?nul?, ?com1? to 
?com9?, and ?lpt1? to ?lpt9' (possibly followed by extensions) are also 
bad.  You can Google "PRN filename in Windows" to find lots of people 
confused by this.  One page I get is

https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

but there's no guarantee that will work five minutes from now.

Duncan Murdoch
#
Thank you. I was just replying my own message with the same information.
Sorry for not doing the research properly before filing.

Cheers
Joris

On Sat, Mar 24, 2018 at 11:36 AM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

  
    
#
Sorry for coming back at this, but would it make sense to have
file.exists() return FALSE when it only finds one of these device names?
Using backslashes to escape the dots makes file.exists() return the correct
result. I got caught by this when I created file names based on a set of
stock market tickers, so I can imagine this could happen to other people
too.

Cheers
Joris
On Sat, Mar 24, 2018 at 11:38 AM, Joris Meys <jorismeys at gmail.com> wrote: