Another way to build functions "from scratch" :
> func<-'x^2+5'
> funcderiv<- D(parse(text=func), 'x') )
> newtparam <- function(zvar) {}
> body(newtparam)[2] <- parse(text=paste('newz <-
(',func,')/eval(funcderiv)',collapse=''))
> body(newtparam)[3] <- parse(text=paste('return(invisible
Creating expressions and functions dynamically can be
tricky. Usually I use functions like call(), substitute(),
and formals(); very occasionally I use parse(text=).
Here is one way to make a family of functions that differ
only in the default value their their argument:
> funsA <- lapply(1:3,
On 05/10/2011 10:57 AM, honeyoak wrote:
it is possible to dynamically create functions in R using lists? what I want
to do is something like this:
a = list()
for (i in 1:10) a[[i]] = function(seed = i) runif(seed)
so that when I call a[i] I get random draws 1,2,i unfortunately
Hi,
On Wed, Oct 5, 2011 at 10:57 AM, honeyoak wrote:
> it is possible to dynamically create functions in R using lists? what I want
> to do is something like this:
>
> a = list()
> for (i in 1:10) a[[i]] = function(seed = i) runif(seed)
>
> so that when I call a[i] I get random draws 1,
4 matches
Mail list logo