Bug 14078 - file_path_as_absolute duplicates "/"
file_path_as_absolute duplicates "/"
Status: CLOSED NOT REPRODUCIBLE
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific
old
ix86 (32-bit) Windows 32-bit
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-11-22 23:59 UTC by Jitterbug compatibility account
Modified: 2009-11-22 23:59 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2009-11-22 23:59:53 UTC
From: joehl@web.de
Full_Name: Jens Oehlschlägel
Version: 2.10.0
OS: Windows XP
Submission from: (NULL) (85.181.157.36)


file_path_as_absolute duplicates "/" for files in the root path, 
which goes back to the fact that file.path(dirname(x), basename(x)) 
currently is not guaranteed to restore x


> x <- "d:/x.RDAta"
> file_path_as_absolute(x)
[1] "d://x.RData"
> file.path(dirname(x), basename(x))
[1] "d://x.RData"
> dirname(x)
[1] "d:/"

> x <- "/"
> file.path(dirname(x), basename(x))
[1] "//"

a possible fix would be to use gsub in file.path before returning, as in 
gsub("/+","/","d://x.RData")

This would 
- standardize the path returned, e.g. help searching for this path in another
one
- make sure we can use that path in setwd(), because
> setwd("//")
Error in setwd("//") : cannot change working directory
> file.create("//a.txt")
[1] FALSE
Warning message:
In file.create("//a.txt") :
  cannot create file '//a.txt', reason 'Invalid argument'



Also note that the help on basename says

"
basename removes all of the path up to the last path separator (if any).
dirname returns the part of the path up to (but excluding) the last path
separator, or "." if there is no path separator. 
"

but obviously there is an undocumented exception for the root path (I guess to
have dirname always return a valid path that we can use in e.g. setwd())

> basename("/")
[1] ""
> dirname("/")
[1] "/"


It is not easy to understand that dirname/basename
- neither always split a string into a path and a file component (since in
"/a/b/" it avoids empty basename and "b" goes to basename)
- nor always split a string into the last token in basename and the rest in
dirname (since it avoids empty rest in "/")
So whatever the rules are, it would be helpful to find them in the help,
because
- not everyone knows what basename / dirname usually do under unix (IEEE Std
1003.1)
- R is not following IEEE Std 1003.1 (since basename("/")=="" while IEEE
requires "/")

Help should also explain why and what happens to "\\\\servername", is that
dirname, is that basename? Currently we have
> dirname(x)
[1] "."
> basename(x)
[1] "\\\\asdfasdf"
> file.path(dirname(x), basename(x))
[1] "./\\\\asdfasdf"


> version
               _                            
platform       i386-pc-mingw32              
arch           i386                         
os             mingw32                      
system         i386, mingw32                
status                                      
major          2                            
minor          10.0                         
year           2009                         
month          10                           
day            26                           
svn rev        50208                        
language       R                            
version.string R version 2.10.0 (2009-10-26)

Comment 1 Jitterbug compatibility account 2009-11-25 19:28:00 UTC
NOTES:
 Presumably about tools::file_paths_as_absolute (package tools is nowhere
mentioned).
The case of a file in a top-level directory was fixed in R 2.10.0 patched,
*but*
- any decent file system understands //, and even Windows seems to.
- most of the irrelevant claims about basename/dirname are misreadings, and
  in any case, file_paths_as_absolute is not using dirname: it was getwd() that
  gave the extra /
- no one mentioned POSIX, and these functions are not based on POSIX functions.
Comment 2 Jitterbug compatibility account 2009-11-25 19:28:13 UTC
Audit (from Jitterbug):
Wed Nov 25 12:30:55 2009	ripley	moved from incoming to not-reproducible-Windows
Wed Nov 25 13:28:13 2009	ripley	changed notes