From dmurdoch at pair.com  Mon Jul 21 16:18:16 2003
From: dmurdoch at pair.com (Duncan Murdoch)
Date: Mon Jul 21 21:14:23 2003
Subject: [Rd] Bug in file.copy: overwrite=FALSE ignored (PR#3529)
In-Reply-To: <sfdohvkqc92tmr3gorticeq4pdoiq214at@4ax.com>
References: <200307211727.h6LHRYJH017824@pubhealth.ku.dk>
	<3F1C2ABF.5050402@statistik.uni-dortmund.de>
	<sfdohvkqc92tmr3gorticeq4pdoiq214at@4ax.com>
Message-ID: <e0fohv87e6cfd7i9u9eht8r3mm7otvl8r9@4ax.com>

On Mon, 21 Jul 2003 14:57:36 -0400, Duncan Murdoch <dmurdoch@pair.com>
wrote :

>Here's my rewrite:
>
>file.copy <- function(from, to, overwrite=FALSE)
>{
>    if (!(nf <- length(from))) stop("no files to copy from")
>    if (!(nt <- length(to)))   stop("no files to copy to")
>    if (nt == 1 && file.exists(to) && file.info(to)$isdir)
>        to <- file.path(to, from)
>    else if (nf > nt)  stop("more `from' files than `to' files")
>    if(nt > nf) from <- rep(from, length = nt)
>    if (!overwrite) okay <- !file.exists(to)
>    else okay <- rep(TRUE, length(to))
>     
>    file.create(to[okay])
>    okay[okay] <- file.append(to[okay], from[okay])
>    okay
>}

This isn't quite right either; it doesn't handle the case of no
eligible files or the case of copying a file onto itself properly.
The first is easy to fix (copying Uwe's test);  I think I'll just make
the second illegal.

Duncan Murdoch


[Rd] Bug in file.copy: overwrite=FALSE ignored (PR#3529)
Duncan Murdoch