On Thu, Mar 15, 2012 at 12:58 PM, Rui Barradas <rui1...@sapo.pt> wrote: > Hello, > >> >> Hi Emily, >> >> Yes (see below), but you might be better off by writing a simple >> function. Here are examples both ways (usually eval parse is highly >> discouraged). >> >> Cheers, >> >> Josh >> > > Yes, eval/parse is discouraged but there's a way of using it, > that is less troublesome, to create a function. > > (Maybe Emily was thinking of symbolic mathematics software - my personal > favorite is > Maple but there is also open source Maxima) > > > makefun <- function(text){ > x <- numeric() > function(x) eval(parse(text=text)) > } > > txt <- 'x^2 + x + 5' > > g <- makefun(txt)
Another way to do this which uses parse but not eval is: g2 <- function(x) {} body(g2) <- parse(text = txt) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org 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.