[R] file.copy

Muhuri, Pradip (SAMHSA/CBHSQ) Pradip.Muhuri at samhsa.hhs.gov
Fri Nov 14 13:07:27 CET 2014


Hello,

Here is something (file.copy) trivial but does not seem to work.  I could not figure out what I am doing wrong.  

The R script below creates folders (fromFolder and toFolder) and finds the list of files (list.of.files) to be copied to the toFolder, which I have verified using the print ()  command. But, the issue is that the file.copy() command does not work.  

Both the R.script and the console are shown below.

Any help/hints will be appreciated.

Thanks,

Pradip Muhuri

#########################  R script  #####################################################
#file.copy.R

#identify the folders
fromFolder <- "H:/R/cis_study"
toFolder <- "F:/cis_study_backup"

# find the list of files to copy 
list.of.files <- list.files(fromFolder, ".R$")

# print objects
print(c(fromFolder, toFolder, list.of.files))
options(warn=1)

# copy the files to the toFolder  - THIS DOES NOT WORK WHILE EVERYTHING PRIOR HAS WORKED
file.copy(list.of.files, toFolder)



#####################  Below is from console ###################
#file.copy.R
> 
> #identify the folders
> fromFolder <- "H:/R/cis_study"
> toFolder <- "F:/cis_study_backup"
> 
> # find the list of files to copy 
> list.of.files <- list.files(fromFolder, ".R$")
> 
> # print objects
> print(c(fromFolder, toFolder, list.of.files))
 [1] "H:/R/cis_study"          "F:/cis_study_backup"    
 [3] "anl.in.scope_111114.R"   "create.oid.data.frame.R"
 [5] "create_xd2012.R"         "file.copy.R"            
 [7] "further.data.R"          "mrj.in.scope_111214.R"  
 [9] "oid.in.scope_111114.R"   "oid_cohort.R"           
[11] "warning.max.R"           "xdate.R"                
[13] "years.before.anl.init.R" "years.before.mrj.init.R"
[15] "years.before.oid.init.R"
> options(warn=1)
> 
> # copy the files to the toFolder  - THIS DOES NOT WORK WHILE EVERYTHING PRIOR HAS WORKED
> file.copy(list.of.files, toFolder)
Warning in file.copy(list.of.files, toFolder) :
  problem copying .\anl.in.scope_111114.R to F:\cis_study_backup\anl.in.scope_111114.R: No such file or directory
(other similar warning messages are not shown)



Pradip K. Muhuri, PhD
SAMHSA/CBHSQ
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
Tel: 240-276-1070
Fax: 240-276-1260



More information about the R-help mailing list