[R] turning a list into a function's params

Rolf Turner r.turner at auckland.ac.nz
Mon Sep 14 04:49:39 CEST 2009


On 14/09/2009, at 2:34 PM, Jack Tanner wrote:

> Apologies for the noob question. I need to split setting up a plot  
> and drawing
> it into two functions. One determines the properties of a plot  
> (data, axis,
> labels, etc.), and the other plots it (using a preferred device, image
> dimensions, etc.).
>
> get.props = function() {
>   list(x=x, y=y, xlab="foo", ylab="bar")
> }
>
> myplot = function() {
>   props = get.props()
>   plot(props) # Doesn't work
> }
>
> What's the right way to call plot() with all the components of  
> props broken out
> as separate parameters to plot()? Note that the components of props  
> may be
> different from call to call (sometimes there's only x data,  
> sometimes there's no
> ylab, etc.).
>
> Thanks in advance for your time and help.

do.call(plot,props)

See ?do.call .

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}




More information about the R-help mailing list