functions and strings
yes you're right, maybe this is better
f <- function(x){sin(x)+exp(x)}
strng <- gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)
sub('^[[:space:]]+', '', strng)
[1] "sin(xyz) + exp(xyz)" Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Robin Hankin" <r.hankin at noc.soton.ac.uk> To: "Dimitris Rizopoulos" <dimitris.rizopoulos at med.kuleuven.be> Cc: "Robin Hankin" <r.hankin at noc.soton.ac.uk>; <r-help at r-project.org> Sent: Wednesday, September 13, 2006 9:54 AM Subject: Re: [R] functions and strings
Hi Dmitris thanks for this but it's not quite right:
f <- function(x){sin(x)+exp(x)}
strng <- gsub("x", "xyz", deparse(body(f))[2])
sub('^[[:space:]]+', '', strng)
[1] "sin(xyz) + exyzp(xyz)" and I would want "sin(xyz) + exp(xyz)" On 13 Sep 2006, at 08:45, Dimitris Rizopoulos wrote:
strng <- gsub("x", "xyz", deparse(body(f))[2])
sub('^[[:space:]]+', '', strng)
-- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm