[R] functions and strings
Robin Hankin
r.hankin at noc.soton.ac.uk
Wed Sep 13 10:22:58 CEST 2006
Hi Dmitris, Thierry,
I'm getting there but it's still not quite right if f() includes
something like x^2:
f <- function(x){exp(x^2)}
>>
gsub("(x)", "(xyz)", deparse(body(f))[2], fixed = TRUE)
[1] " x^2"
[I don't care about the spaces]
also,
I can't quite see how to implement Thierry's suggestion about
changing the letter "x" into a letter that does not occur in f(),
because of the
following example:
f <- function(x){abcdefghijklmnopqrstuvwxyz(x^2)}
On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote:
> 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
>
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
More information about the R-help
mailing list