[R] Removing directory?

Henrik Bengtsson hb at stat.berkeley.edu
Thu Mar 1 00:52:12 CET 2007


Thanks!  ...as the help indeed says:

     If 'recursive = FALSE' directories are not deleted, not even empty
     ones.

It works;

> dir.create("foo")
> file.info("foo")
    size isdir mode               mtime               ctime               atime
foo    0  TRUE  777 2007-02-28 15:50:33 2007-02-28 15:50:33 2007-02-28 15:50:33
> print(file.remove("foo", recursive=TRUE))
[1] FALSE
> file.info("foo")
    size isdir mode               mtime               ctime               atime
foo    0  TRUE  777 2007-02-28 15:50:33 2007-02-28 15:50:33 2007-02-28 15:50:33
> print(unlink("foo", recursive=TRUE))
[1] 0
> file.info("foo")
    size isdir mode mtime ctime atime
foo   NA    NA <NA>  <NA>  <NA>  <NA>
> file.exists("foo")
[1] FALSE

/Henrik

On 2/28/07, James W. MacDonald <jmacdon at med.umich.edu> wrote:
> I think you want to add a recursive = TRUE to your call to unlink().
>
> Best,
>
> Jim
>
> Henrik Bengtsson wrote:
> > Hi,
> >
> > I'm trying to remove/delete a directory usingR.  I've tried the
> > following with no success:
> >
> > % Rterm --vanilla
> >
> >>getwd()
> >
> > [1] "C:/Documents and Settings/hb/braju.com.R/aroma.affymetrix/test"
> >
> >
> >>dir.create("foo")
> >>file.info("foo")
> >
> >     size isdir mode               mtime               ctime               atime
> > foo    0  TRUE  777 2007-02-28 14:52:10 2007-02-28 14:52:10 2007-02-28 14:52:10
> >
> > # Using file.remove()
> >
> >>res <- sapply(c("foo", "foo/", "foo\\", "./foo", "./foo/"), file.remove)
> >>res
> >
> >    foo   foo/  foo\\  ./foo ./foo/
> >  FALSE  FALSE  FALSE  FALSE  FALSE
> >
> > # Using unlink()
> >
> >>res <- sapply(c("foo", "foo/", "foo\\", "./foo", "./foo/"), unlink)
> >>res
> >
> >    foo   foo/  foo\\  ./foo ./foo/
> >      1      0      0      1      0
> >
> > # Directory is still there
> >
> >>file.info("foo")
> >
> >     size isdir mode               mtime               ctime               atime
> > foo    0  TRUE  777 2007-02-28 14:52:10 2007-02-28 14:52:10 2007-02-28 14:52:10
> >
> > I've tried the above from a different directory too, i.e.
> > setwd("C:/"), with no success.  Using absolute pathnames the same.
> >
> > This is on WinXP R v2.4.1:
> >
> >
> >>sessionInfo()
> >
> > R version 2.4.1 Patched (2007-01-13 r40470)
> > i386-pc-mingw32
> >
> > locale:
> > LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MON
> > ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> >
> >
> > attached base packages:
> > [1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
> > [7] "base"
> >
> > Thanks
> >
> > Henrik
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
> --
> James W. MacDonald
> University of Michigan
> Affymetrix and cDNA Microarray Core
> 1500 E Medical Center Drive
> Ann Arbor MI 48109
> 734-647-5623
>
>
>
> **********************************************************
> Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
>



More information about the R-help mailing list