[R] substitute in a named expression

Søren Højsgaard Soren.Hojsgaard at agrsci.dk
Wed Jun 22 23:33:03 CEST 2005


I have a 'named expression' like
  expr <- expression(rep(1,d))
and would like to replace the argument d with say 5 without actually evaluating the expression. So I try  substitute(expr, list(d=5)) in which case R simply returns expr which when I 'evaluate' it gives
 eval(expr)
 Error in rep.default(1, d) : invalid number of copies in rep()

I've looked at ?substitute and ?expression (and other places) for ideas, but - well I guess there are some details which I haven't quite understood. Can anyone point me in the right direction?
Thanks
Søren




More information about the R-help mailing list