[Rd] Limitation of dirname() and basename()
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Mar 27 08:50:50 CEST 2007
These functions work as they should: did you not read the help page which
explicitly tells you what happens in this case?
The Unix originals work in the same way:
gannet% dirname /my/path/
/my
Please DO study the R posting guide and do the homework requesting of you
before posting.
On Mon, 26 Mar 2007, cstrato wrote:
> Dear all,
>
> I have already twice encountered a case which I consider a limitation of
> dirname() and basename().
>
> In my functions I have a parameter "outfile" which e.g. tells where a file
> should be stored. Usually "outfile" is of the form:
> oufile = "/my/path/myname.txt"
>
> > outfile <- "/my/path/myname.txt"
> > dirname(outfile)
> [1] "/my/path"
> > basename(outfile)
> [1] "myname.txt"
>
> However, in addition I want to be able to define the path only, while
> creating the name "myname.txt" automatically.
> Sorrowly, I get the following:
>
> > outfile <- "/my/path/"
> > dirname(outfile)
> [1] "/my"
> > basename(outfile)
> [1] "path"
>
> It would be great if dirname() and basename() could recognize:
> dirname("/my/path/") = /my/path/
> basename(""/my/path/") = ""
> i.e. they should be able to recognize a trailing "/".
Not according to the documentation.
>
> Best regards
> Christian
> _._._._._._._._._._._._._._._._
> C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
> V.i.e.n.n.a A.u.s.t.r.i.a
> _._._._._._._._._._._._._._._._
--
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
More information about the R-devel
mailing list