[R] Distinguishing variables from functions with the same name
Berwin A Turlach
berwin at maths.uwa.edu.au
Fri Feb 13 18:25:25 CET 2009
G'day Stavros,
On Fri, 13 Feb 2009 11:11:28 -0500
Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> On Fri, Feb 13, 2009 at 10:47 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
> > See ?get and try:
>
> Interesting. I hadn't paid attention to the 'mode' argument before.
>
> Where would it be advisable to use anything but mode='any' or
> mode='function'?
I guess the answer to this question is more often than not in the source. :)
On my machine:
berwin at berwin-nus1:/opt/src/R-devel-src/src/library$ find . -name "*.R" -type f | xargs grep "get(" \
> | grep mode | grep -v function | grep -v all
./tools/R/QC.R: al <- get(al, envir = code_env, mode = "list")
./tools/R/QC.R: al <- get(al, envir = ns_env, mode = "list")
./tools/R/QC.R: al <- get(al, envir = data_env, mode = "list")
./utils/R/Sweave.R: syntax <- get(syntax, mode="list")
./utils/R/Sweave.R: syntax <- get(sname, mode = "list")
./utils/R/Sweave.R: s <- get(sname, mode="list")
./utils/R/str.R: str(get(nam, envir = E, mode = M),
./stats/R/model.tables.R: tables[[i]] <- tapply(data, model[model.cols[[i]]], get(fun))
./stats/R/models.R: ## get(contr.funs[1 + isOF[nn]])(nlevels(data[[nn]]))
./base/R/get.R: .Internal(get(x, envir, mode, inherits))
./base/R/get.R: .Internal(mget(x, envir, mode, ifnotfound, inherits))
./base/R/match.fun.R: FUN <- get(as.character(FUN), mode =
"any", envir = envir)
The first few hits seem to indicate examples where it is necessary
to look specifically for a list.
Cheers,
Berwin
More information about the R-help
mailing list