Somewhere along the way tempdir()
prepends an extra forward slash before the directory at the end of the tree. Is there any reason for this and are there any cases in which it matters? According to this answer from another site, double slashes in a directory tree don't matter (but they do at the start of a path), so why does R
on osx add an extra one?
Could this be considered a bug or is there a situation where it's necessary? In the example both paths resolve correctly:
tempdir()
[1] "/var/folders/ck/1x5j5jvx5mq17clf5r32gg540000gn/T//Rtmpp6VKKK"
normalizePath( tempdir() )
[1] "/private/var/folders/ck/1x5j5jvx5mq17clf5r32gg540000gn/T/Rtmpp6VKKK"
setwd( tempdir() )
write.table("" , file="This is a test.txt")
system( paste0( "cd " , tempdir() , "; ls -a" ) )
.
..
This is a test.txt
system( paste0( "cd " , normalizePath( tempdir() ) , "; ls -a" ) )
.
..
This is a test.txt
As an aside, I realise that it's not very relevant for this site, but perhaps someone with more osx
experience could shed light on why normalizePath()
changes /var
to /private/var
? Is this to do with aliases?
This is most likely a bug in the implementation of tempdir
. Per the function documentation[1]:
The environment variables
TMPDIR
,TMP
andTEMP
are checked in turn and the first found which points to a writable directory is used: if none succeeds‘/tmp’
is used.
TMPDIR
, by default, contains a trailing slash which tempdir()
seems to not notice when composing its result. A better implementation would remove the trailing slash first, if it exists.
And yes, on Mac OS X, /tmp
is a symbolic link to /private/tmp
.
[1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/tempfile.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With