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" <[EMAIL PROTECTED]>
To: "Dimitris Rizopoulos" <[EMAIL PROTECTED]>
Cc: "Robin Hankin" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
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

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to