Hi,

Many thanks for the responses which solved my problem.

Fyi, my actual application is

copulaClayton <- function(u, v, alpha) 
  (u^-alpha + v^-alpha - 1)^(-1/alpha)
g <- function(){}
body(g) <- do.call("substitute", list(body(copulaClayton), 
  list(u = as.name("w"), v = quote(pnorm(var - qnorm(w))))))
formals(g) <- alist(w=, var=, alpha=)
g

and the substitutions seem to be working fine.

Thanks to 
Liaw, Andy [EMAIL PROTECTED]
Dimitris Rizopoulos [EMAIL PROTECTED]
Bert Gunter [EMAIL PROTECTED] and
Thomas Lumley [EMAIL PROTECTED],
Gabor Grothendieck <[EMAIL PROTECTED]>

Regards,

John.

-----Original Message-----
From: Gavin, John 
Sent: 29 September 2004 12:17
To: '[EMAIL PROTECTED]'
Subject: defining a template for functions via do.call and substitute.

Hi,

Given a function

  fun <- function(a, b) a + b

how do I generate the function 'function(x, y) x + y'?

Working from the help files and Bill Venables' R-news article (June 2002),
I have tried various permutations with substitute without success. 
e.g.
  do.call("substitute", list(fun, list(a = as.name("x"), b = as.name("y"))))

Regards,

John.

John Gavin <john.gavin at ubs.com>,
Quantitative Risk Models and Statistics,
UBS Investment Bank, 6th floor, 
100 Liverpool St., London EC2M 2RH, UK.
Phone +44 (0) 207 567 4289
Fax   +44 (0) 207 568 5352

Visit our website at http://www.ubs.com

This message contains confidential information and is intend...{{dropped}}

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to