My function needs to do two things with the filename: First, create the plot file. For this, Rplot%03d is OK because it is correctly interpreted by the graphics device.
Second, generate a text string referring to this filename. This is where I need to convert Rplot%03d to, say, Rplot001. I am assuming that it is implemented internally by looking at the files in the current directory with some regular expression search, and incrementing the end number as needed. I wonder if there's a high level function to perform this task. Best, baptiste On 21 August 2010 13:35, kees duineveld <kees.duinev...@gmail.com> wrote: > Not sure what you want. Plot does that automatically. It seems to use > path.expand() to make the %03d expansion. Not that path.expand() is > documented to do this, but it seem to work. > > Kees > > On Sat, 21 Aug 2010 13:04:54 +0200, baptiste auguie > <baptiste.aug...@googlemail.com> wrote: > >> Dear list, >> >> I'm using the brew package to generate a report containing various >> plots. I wrote a function that creates a plot in png and pdf formats, >> and outputs a suitable text string to insert the file in the final >> document using the asciidoc syntax, >> >> <% >> tmp <- 1 >> makePlot = function(p, name=paste("tmp",tmp,sep=""), width=300) >> { >> png(paste(name,".png",sep="")) >> print(p) >> dev.off() >> pdf(paste(name,".pdf",sep="")) >> print(p) >> dev.off() >> >> cat(noquote(paste('image:',name,'.png["',name,'",width=',width,',link="',name,'.pdf"]',sep=""))) >> tmp <<- tmp + 1 >> } >> %> >> >> The resulting html file contains a thumbnail of the png file, with a >> link to the pdf file. >> >> I'm not happy with my default filename for the graphics. Is there a >> way to expand the default filename of R graphic devices? I would like >> to call it like this, >> >> >> makePlot = function(p, name="Rplot%03d", width=300) >> { >> >> real.name = expandName(name) # function needed here >> png(paste(name,".png",sep="")) >> print(p) >> dev.off() >> pdf(paste(name,".pdf",sep="")) >> print(p) >> dev.off() >> >> cat(noquote(paste('image:',real.name,'.png["',real.name,'",width=',width,',link="',real.name,'.pdf"]',sep=""))) >> } >> >> >> Sincerely, >> >> baptiste >> >> ______________________________________________ >> 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. > ______________________________________________ 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.