[R] formula argument evaluation
Adrian Dușa
dusa.adrian at unibuc.ro
Tue Apr 12 12:24:23 CEST 2016
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:
# this works
> foo(A + B)
[1] "A + B"
# but this doesn't
> foo(A + B => C)
Error: unexpected '=' in "foo(A + B ="
Can I prevent it from evaluating the "=" sign?
The addition sign "+" hasn't been evaluated, and I was hoping the "=" would
not get evaluated either. The "=>" sign is important for other purposes,
not related to this example.
Thank you in advance,
Adrian
--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania
[[alternative HTML version deleted]]
More information about the R-help
mailing list