[R] R-level expansion of Rplot%03d.png
baptiste auguie
baptiste.auguie at googlemail.com
Sat Aug 21 13:04:54 CEST 2010
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
More information about the R-help
mailing list