Hi everyone, I have written a script which exports my graphs as a PDF file using the function pdf(). For instance, I run the script and it exports a PDF called "version 1". Then, I have got a new dataset and want to run the script again. What it usually does is overwriting "version 1". But 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? Thanks in advance, Chris -- View this message in context: http://n4.nabble.com/Exporting-PDF-tp2015263p2015263.html Sent from the R help mailing list archive at Nabble.com.
a little searching would have found: ?file.exists On Sun, Apr 18, 2010 at 7:54 PM, chrisli1223 <chrisli@austwaterenv.com.au>wrote:> > Hi everyone, > > I have written a script which exports my graphs as a PDF file using the > function pdf(). > > For instance, I run the script and it exports a PDF called "version 1". > Then, I have got a new dataset and want to run the script again. What it > usually does is overwriting "version 1". But 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? > > Thanks in advance, > Chris > -- > View this message in context: > http://n4.nabble.com/Exporting-PDF-tp2015263p2015263.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Problem solved. I combined file.exists and while loop to create version number. Thank you very much for your help. -- View this message in context: http://n4.nabble.com/Exporting-PDF-tp2015263p2015366.html Sent from the R help mailing list archive at Nabble.com.
Polwart Calum (County Durham and Darlington NHS Foundation Trust)
2010-Apr-20 19:37 UTC
[R] Exporting PDF
> 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}}