[R] Unlink a directory with leading and trailing space
mikewhite.diu at btconnect.com
Wed Jan 4 16:23:04 CET 2006
Thanks for your suggestions.
I am using Windows 2000 Professional with R 2.1.0 and have replicated the
problem with the code below which creates the directory " testdir "
# pathin is the parent path and ends with /
pathtest<-paste(pathin, "testdir", "/") # I forgot to include sep=""
dir.create(pathtest) # creates directory " testdir "
The directory cannot be deleted with the short name as below
>From the console I have also tried
rmdir " testdir "
but without success.
----- Original Message -----
From: "Prof Brian Ripley" <ripley at stats.ox.ac.uk>
To: "Duncan Murdoch" <murdoch at stats.uwo.ca>
Cc: "Mike White" <mikewhite.diu at btconnect.com>; <R-help at stat.math.ethz.ch>
Sent: Wednesday, January 04, 2006 1:49 PM
Subject: Re: [R] Unlink a directory with leading and trailing space
> On Wed, 4 Jan 2006, Duncan Murdoch wrote:
> > On 1/3/2006 11:01 AM, Mike White wrote:
> >> Using paste without defining a separator to generate a directory name
> >> dir.create, I have inadvertently created a directory with a leading and
> >> trailing space. I cannot now delete this directory with unlink or from
> >> Windows explorer. Any help deleting this directory would be
> > What name did you end up with? I don't have any problem removing the
> > directory " test " just by right-clicking and choosing Delete. You can
> > also open a command window, and put the name in quotes, e.g.
> > rmdir " test "
> But AFAICS Windows always drops trailing spaces.
> > dir.create(" test ")
> > dir()
>  " test"
> and similarly at the command prompt.
> > I do see the problem in unlink().
> Which in turn is a problem in MSVCRT's _rmdir. The usual trick here is
> to use short path names instead, and that works e.g.
> unlink("TEST~1", recursive=TRUE)
> R-devel has a shortPathName() function, so you could do
> unlink(shortPathName(" test "), recursive = TRUE)
> (but I've now fixed the source code to use the short name).
> 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-help