[R] functions and strings

Romain Francois rfrancois at mango-solutions.com
Wed Sep 13 09:44:00 CEST 2006


Robin Hankin wrote:
> Hi
>
> If
>
> string <- "xyz"
> f <- function(x){1 + sin(cos(x)) + exp(x^2)}
>
> How do I manipulate "string" and f() to give the string
>
> "1 + sin(cos(xyz)) + exp(xyz^2)"
>
> ?
>   
Hi,

Here what i'll do :

f <- function(x){
  sprintf("1 + sin(cos(%s)) + exp(%s^2)", x, x)
}

Cheers,

Romai


> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>



More information about the R-help mailing list