[R] Help with evaluation of expressions
Dieter Menne
dieter.menne at menne-biomed.de
Fri Jun 2 16:09:29 CEST 2006
Michael Conklin <michael.conklin <at> markettools.com> writes:
>
> I have searched through the help files and I have been unsuccessful in
> solving this problem.
>
> I am trying to create a small wrapper function that will go around a
> call to a plot function and create a windows metafile in the directory
> and also write the name of the file to a text file. The purpose is to
> efficiently bring a large number of plots into powerpoint. I am using
> platform
Try this variant. Note that I am using emf instead of wmf, it's a bit more
stable. And I had to prepare an undecorated filename since savePlot has special
ideas about appending appendixes.
Please, if you post, provide a full working demo example next time, not only the
function. There are only few genius who can see the right way without firing up
the gui.
Dieter
------
plotSlide<-function(pltexpr){
expr<-as.expression(pltexpr)
numslide<-length(dir(pattern="emf"))+1
fname0<-paste("SG",numslide,sep="")
fname<-paste(fname0,".emf",sep="")
dirlist<-dir(pattern="SlideList.txt")
if (length(dirlist)==1){
fs<-file("SlideList.txt",open="at")
write(paste(fname,"Graph",sep=","),file=fs)
close(fs)} else {
write(paste(fname,"Graph",sep=","),file="SlideList.txt")
}
p=eval(pltexpr)
if (is.null(p)) {
savePlot(fname0,type="emf")
} else {
trellis.device(device = win.metafile, theme = "col.whitebg", new =
TRUE, retain = FALSE, file=fname,width=6,height=4)
print(p)
}
dev.off()
fname
}
plotSlide(
plot(rnorm(100))
)
library(lattice)
plotSlide(
xyplot(Sepal.Length ~ Petal.Length, data = iris)
)
More information about the R-help
mailing list