[R] using bquote to construct function

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Oct 2 07:14:39 CEST 2008

Hi, R-help,

(sessionInfo at the end)

I'm trying to construct a function using bquote and running into a 
strange error message. As an example, what I would like to do is this:

z <- 2
eval(bquote(function(x, y) { x^.(z) + y }))(2, 3)

However, I get the following:

Error in eval(expr, envir, enclos) :
   invalid formal argument list for "function"

However, if I change the command to following, it works:

z <- 2
eval(bquote(function(x) { x^.(z) }))(2)
# [1] 4

In other words, I remove the second argument. Is there a workaround for 
this without using eval(parse(text = ))?



 > sessionInfo()
R version 2.7.2 (2008-08-25)

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

More information about the R-help mailing list