Re: [R] formula argument evaluation

2016-04-14 Thread Adrian Dușa
Thanks Bill, it's very useful to know how parsing and evaluation works. It seems that quoting is the least complicated solution which is guaranteed to work. Best, Adrian On 13 Apr 2016 6:04 p.m., "William Dunlap" wrote: > %=>% would have precendence ('order of operations')

Re: [R] formula argument evaluation

2016-04-13 Thread William Dunlap via R-help
%=>% would have precendence ('order of operations') problems also. A + B %=>% C is equivalent to A + ( B %=>% C) and I don't think that is what you want. as.list(quote(A + B %=>% C)) shows the first branch in the parse tree. The following function, str.language, shows the entire parse

Re: [R] formula argument evaluation

2016-04-13 Thread Adrian Dușa
I suppose it would work, although "=>" is rather a descriptive symbol and less a function. But choosing between quoting: "A + B => C" and a regular function: A + B %=>% C probably quoting is the most straightforward, as the result of the foo() function has to be a string anyways (which is parsed

Re: [R] formula argument evaluation

2016-04-12 Thread Richard M. Heiberger
Would making it regular function %=>%, using "%" instead of quotes, work for you? On Tue, Apr 12, 2016 at 11:09 AM, Adrian Dușa wrote: > On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch > wrote: >> [...] >> >> It never gets to evaluating it. It

Re: [R] formula argument evaluation

2016-04-12 Thread Adrian Dușa
On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch wrote: > [...] > > It never gets to evaluating it. It is not a legal R statement, so the parser signals an error. > If you want to pass arbitrary strings to a function, you need to put them in quotes. I see. I thought it

Re: [R] formula argument evaluation

2016-04-12 Thread Keith Jewell
On 12/04/2016 11:24, Adrian Dușa wrote: I have a simple function such as: foo <- function(x) { call <- lapply(match.call(), deparse) testit <- capture.output(tryCatch(eval(x), error = function(e) e)) if (grepl("Error", testit)) { return(call$x) } } and I would like

Re: [R] formula argument evaluation

2016-04-12 Thread Duncan Murdoch
On 12/04/2016 6:24 AM, Adrian Dușa wrote: I have a simple function such as: foo <- function(x) { call <- lapply(match.call(), deparse) testit <- capture.output(tryCatch(eval(x), error = function(e) e)) if (grepl("Error", testit)) { return(call$x) } } and I would

[R] formula argument evaluation

2016-04-12 Thread Adrian Dușa
I have a simple function such as: foo <- function(x) { call <- lapply(match.call(), deparse) testit <- capture.output(tryCatch(eval(x), error = function(e) e)) if (grepl("Error", testit)) { return(call$x) } } and I would like to detect a formula when x is not an object: