Displaying 1 result from an estimated 1 matches for "fpost".
Did you mean:
post
2007 Jan 05
5
eval(parse(text vs. get when accessing a function
...2204.html
was in reply to accessing a list).
Suppose I have similarly called functions, except for a postfix. E.g.
f.1 <- function(x) {x + 1}
f.2 <- function(x) {x + 2}
And sometimes I want to call f.1 and some other times f.2 inside another
function. I can either do:
g <- function(x, fpost) {
calledf <- eval(parse(text = paste("f.", fpost, sep = "")))
calledf(x)
## do more stuff
}
Or:
h <- function(x, fpost) {
calledf <- get(paste("f.", fpost, sep = ""))
calledf(x)
## do more stuff
}
Two questions:
1) Why i...