R/file.copy2.R

Defines functions file.copy2

Documented in file.copy2

file.copy2 <- function(from, to) {
##
## 1.  length(from)
##
  nf <- length(from) 
  if(nf<1)stop("no file to copy")
  if(nf>1)
    stop("'file.copy2' can copy only one file per call;  ",
         "length(from) = ", nf) 
##
## 2.  file.exists(from)?  
##
  if(!file.exists(from))return(FALSE) 
##
## 3.  Check 'to' 
##
  {
    if(missing(to)) to <- from
    else {
      nt <- length(to)
      if(nt<1) to <- from
      else
        if(nt>1)
          stop("'file.copy2' can make only one copy;  ",
               "length(to) = ", nt)
    }
  }
##
## 4.  file.exists(to)?  
##
  if(file.exists(to)){
    Dir <- dir(dirname(to))
    To <- basename(to) 
    nch <- nchar(To)
    DIR <- toupper(Dir) 
    to2 <- (toupper(To) == substring(DIR, 1, nch))
    nto2 <- sum(to2)
    To2 <- paste(To, 1:(nto2+1), sep="")
    Exists <- (toupper(To2) %in% DIR)
    to <- To2[!Exists][1] 
  }
##
## 5.  file.copy   
##
  file.copy(from, to) 
}

Try the fda package in your browser

Any scripts or data that you put into this service are public.

fda documentation built on May 2, 2019, 5:12 p.m.