[R] How can I run a function to a piece of text?

2009-10-16 Thread Javier PB
Dear users, I got really stuck trying to apply a function to a piece of code that I created using different string functions. To make things really easy, this is a wee example: x-c(1:10) script-x, trim = 0, na.rm = FALSE##script created by a number of paste() and rep() steps

Re: [R] How can I run a function to a piece of text?

2009-10-16 Thread Sundar Dorai-Raj
Based solely on what you told us, this can be done using eval(parse(text=...)) cmd - sprintf(mean(%s), script) eval(parse(text = cmd)) However, with more context, there may be a better solution. See, for example, install.packages(fortunes) library(fortunes) fortune(parse()) HTH, --sundar On

Re: [R] How can I run a function to a piece of text?

2009-10-16 Thread Alberto Monteiro
Javier PB wrote: I got really stuck trying to apply a function to a piece of code that I created using different string functions. To make things really easy, this is a wee example: x-c(1:10) script-x, trim = 0, na.rm = FALSE##script created by a number of paste() and rep()

Re: [R] How can I run a function to a piece of text?

2009-10-16 Thread Henrique Dallazuanna
An alternative could be: do.call(mean, as.list(parse(text = unlist(strsplit(script, , ) On Fri, Oct 16, 2009 at 3:39 PM, Javier PB j.perez-barbe...@macaulay.ac.uk wrote: Dear users, I got really stuck trying to apply a function to a piece of code that I created using different string