1

I have a function which plots 4 graphs based on a data file, each in distinct page of a pdf file. Currently, I need to get one handler for all of them, I mean I prefer my function returns a handler for all these graphs instead of saving them as a pdf file. Is it possible?

It should be noted that I use plot(.), not ggplot2.

Thanks.

user4704857
  • 469
  • 4
  • 18
  • 2
    What do you mean by "handle" and "hander"? Base graphics function do not return objects; they draw directly to the current graphics device. – MrFlick Apr 20 '15 at 17:21
  • 3
    As it stands it's kind of hard to tell what you're asking. Please include a [minimum reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to show what you've tried and what you're after. – Alex A. Apr 20 '15 at 17:22

1 Answers1

1

You could keep your plotting function and its arguments separate, e.g.:

do_plot <- function(formula, dat) {
    plot(formula, data=dat)
    # other plotting commands go here
} 

handle <- list(
  fun=do_plot, 
  arg=list(formula="Sepal.Length~Sepal.Height", data=iris)
)

To actually plot, you would then use do.call:

do.call(handle$fun, handle$arg)
Karsten W.
  • 17,826
  • 11
  • 69
  • 103