Skip to content

how to index statements provided as function args?

3 messages · Dan Kelley, Duncan Murdoch

#
Is there a way to specify a *vector* of statements, as an argument to a
function.  What I'm trying to do is to provide the ability to add elements
to a series of panels drawn by a function.  (As documented, split.screen
does not provide this capability.) My idea is to mimic the 'plot.axes'
argument of filled.contour(), but with indexed statements to be executed.  A
series of tests is given below.  (NOTE: I know that I can use parse() on
character strings, but I'm trying to avoid forcing users of the function to
deal with nested quote marks, and the filled.contour scheme seems elegant to
my eye.)
a
b
a
b
NULL
Error: syntax error

  
    
#
On 15/04/2009 6:31 AM, Dan Kelley wrote:
There are several ways.  expression() converts its arguments into a 
vector of expressions, e.g.

 > e <- expression(cat("a\n"), cat("b\n"))
 > e[[1]]
cat("a\n")
 > eval(e[[1]])
a

Duncan Murdoch

  What I'm trying to do is to provide the ability to add elements
#
That works perfectly.  Thanks very much!!
Duncan Murdoch-2 wrote: