[R] defining a template for functions via do.call and substitute.
john.gavin@ubs.com
john.gavin at ubs.com
Thu Sep 30 12:43:30 CEST 2004
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 [andy_liaw at merck.com]
Dimitris Rizopoulos [dimitris.rizopoulos at med.kuleuven.ac.be]
Bert Gunter [gunter.berton at gene.com] and
Thomas Lumley [tlumley at u.washington.edu],
Gabor Grothendieck <ggrothendieck at myway.com>
Regards,
John.
-----Original Message-----
From: Gavin, John
Sent: 29 September 2004 12:17
To: 'r-help at stat.math.ethz.ch'
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}}
More information about the R-help
mailing list