Elaine Jones
2009-Feb-26 21:32 UTC
[R] Substituting in a variable file name in a Windows system command
I am running R version 2.8.1 on Windows XP OS. I generate and write a .csv file from my R script. Then the following command works to upload it to a remote server using a windows batch file that carries out the ftp (among other things). > system("C:/upload_data/uploadq8.bat C:/upload_data/out_2009-02-26.csv", wait=FALSE) I want to set this up to run daily and create a unique filename each day it runs. I write the .csv file with a unique filename by > fname <- paste("out_",Sys.Date(),".csv",sep="") > write.table(config_all5,file=fname,row.names=FALSE, quote=FALSE,sep=","); I can build the string (including quotes) that is the first argument in the system command: > com <- paste('"C:/upload_data/uploadq8table.bat C:/upload_data/',fname,'"', sep="") > com [1] "\"C:/upload_data/uploadq8table.bat C:/upload_data/out_2009-02-26.csv\"", But when I substitute it into the system command I get an error: > system(com, wait=FALSE) Warning in system(com, wait = FALSE) : "C:/upload_data/uploadq8table.bat C:/upload_data/out_2009-02-26.csv" not found > Any suggestions for how to resolve are appreciated! **************** Elaine McGovern Jones ************************ ISC Tape and DASD Storage Products Characterization and Failure Analysis Engineering Phone: 408 284 4853 Internal: 3-4853 jones2@us.ibm.com [[alternative HTML version deleted]]
Duncan Murdoch
2009-Feb-26 23:34 UTC
[R] Substituting in a variable file name in a Windows system command
Elaine Jones wrote:> I am running R version 2.8.1 on Windows XP OS. > > I generate and write a .csv file from my R script. Then the following > command works to upload it to a remote server using a windows batch file > that carries out the ftp (among other things). > > > system("C:/upload_data/uploadq8.bat > C:/upload_data/out_2009-02-26.csv", wait=FALSE) > > I want to set this up to run daily and create a unique filename each day it > runs. I write the .csv file with a unique filename by > > > fname <- paste("out_",Sys.Date(),".csv",sep="") > > > write.table(config_all5,file=fname,row.names=FALSE, > quote=FALSE,sep=","); > > I can build the string (including quotes) that is the first argument in > the system command: >Don't include the quotes.> > com <- paste('"C:/upload_data/uploadq8table.bat > C:/upload_data/',fname,'"', sep="") >Should be com <- paste('C:/upload_data/uploadq8table.bat C:/upload_data/',fname, sep="") Duncan Murdoch> > com > [1] "\"C:/upload_data/uploadq8table.bat > C:/upload_data/out_2009-02-26.csv\"", > > But when I substitute it into the system command I get an error: > > system(com, wait=FALSE) > Warning in system(com, wait = FALSE) : > "C:/upload_data/uploadq8table.bat C:/upload_data/out_2009-02-26.csv" > not found > > > > Any suggestions for how to resolve are appreciated! > > **************** Elaine McGovern Jones ************************ > > ISC Tape and DASD Storage Products > Characterization and Failure Analysis Engineering > Phone: 408 284 4853 Internal: 3-4853 > jones2 at us.ibm.com > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >