From ripley at stats.ox.ac.uk  Fri Oct  3 13:02:39 2008
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 3 Oct 2008 12:02:39 +0100 (BST)
Subject: [Rd] A strange behaviour of file.path in Windows? (PR#13119)
In-Reply-To: <20081003080506.4D9A52834611@mail.pubhealth.ku.dk>
References: <20081003080506.4D9A52834611@mail.pubhealth.ku.dk>
Message-ID: <alpine.LFD.2.00.0810031046390.11618@auk.stats.ox.ac.uk>

On Fri, 3 Oct 2008, pego.enrico at tiscali.it wrote:

> Full_Name: Enrico Pegoraro
> Version: 2.7.2
> OS: Windows (Vista or Xp PRO) Italian
> Submission from: (NULL) (87.4.189.202)
>
>
> If you send these lines of code:
>
> outdir="c:/pippo"
> file.path(outdir,"pluto.html")
>
> R replies correctly:
>
> [1] "c:/pippo/pluto.html"
>
> But if you change the first steps to:
>
> outdir=""
> file.path(outdir,"pluto.html")
>
> R replies (uncorrectly, I think)

> [1] "/c:/pippo/pluto.html"

Not for me!  I get

> outdir=""
> file.path(outdir,"pluto.html")
[1] "/pluto.html"

which is as documented, hence correct.  Furthermore, the code cannot 
possibly give your answer unless 'c:/pippo' has some special status on 
your system, and you haven't told us anything about that.

If you do

file.path("", "c:/pippo", "pluto.html")

you get what you indicate, but that is user error (an empty server/share 
specification).

>
> This problem influence the R2HTML package too, which, if you send a line as:
>
> targetHtml=HTMLInitFile(outdir="",filename="htmlFile",Title ="Title")
>
> in windows it submit an error because of file.path() error.

It will affect any such misuse of file.path, of course.  It really is not 
a good idea to use empty file path elements, especially on Windows[*]. 
If you mean the current directory, use ".".

[*] On Unix // is equivalent to /.  On Windows \\ or // may have a special 
meaning (a share) or be regarded as invalid.  A trailing  / or \ can be 
disastrous.

> Thank you
> Enrico


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] A strange behaviour of file.path in Windows? (PR#13119)
Prof Brian Ripley