Since R provides the file.exists() function for exactly this
purpose, I would recommend avoiding using shell scripts for
such a simple task. file.exists() is a multiplatform solution
to the problem.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Tue, 20 Apr 2010, Polwart Calum (County Durham and Darlington NHS Foundation
Trust) wrote:
I run the script and it exports a PDF called "version 1".
I want it to check if "version 1" already exists. If so,
then I want the new graphs to be exported as
"version 2", and so on.
Is it possible to do it in R?
Someone may know a way. However its certainly possible to execute a command in
linus from R. So you can ls the file (in windows try dir) and see if it
exists, and build a loop round that.
Just bew3are it'll be quick if there is only 1 file. If you have 9999 files it
may slow things down a bit!
Here's my example...
#Example script to check if a file exists (linux system)
filename = "somefile"
fileno = 0
extension= ".pdf"
path="/home/user/"
repeat
{
fullfile= paste(path,filename,fileno,extension, sep="")
if (length (system(paste("ls",fullfile), intern = T)) == 0) break
fileno<-fileno+1
}
#your command to save the file... using 'fullfile' as the filename and path
********************************************************************************************************************
This message may contain confidential information. If yo...{{dropped:21}}
______________________________________________
R-help@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.
______________________________________________
R-help@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.