[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] Removing directory?
From:       "Henrik Bengtsson" <hb () stat ! berkeley ! edu>
Date:       2007-02-28 23:52:12
Message-ID: 59d7961d0702281552t78fd1da3pae3af0f731706546 () mail ! gmail ! com
[Download RAW message or body]

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@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@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. 

______________________________________________
R-help@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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic