Re: [R] Help with evaluation of expressions

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Sat 03 Jun 2006 - 00:09:29 EST

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) )



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 03 01:28:36 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 03 Jun 2006 - 02:10:29 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.