[R] eval(parse(text vs. get when accessing a function

Ramon Diaz-Uriarte rdiaz02 at gmail.com
Sat Jan 6 20:08:45 CET 2007


On 1/6/07, Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Sat, 6 Jan 2007, Ramon Diaz-Uriarte wrote:
(...)

> >
> > cvFunct <- function(whatever, genefiltertype, whateverelse) {
> >      internalGeneSelect <- eval(parse(text = paste("geneSelect",
> >                                             genefiltertype, sep = ".")))
> >
> >      ## do things calling internalGeneSelect,
> > }
>
> That looks like a more complicated alternative to
>
>     get(paste("geneSelect", genefiltertype, sep = "."))
>

Yes, you are right, thanks. Actually, now that I think of it, the
eval(parse(text looks _a lot_ more verbose.


> I would worry about scope in both cases: I think you most likely want
> eval.parent in yours, and to pick an environment for use in get() (but
> the view you have shown is still too narrow for us to know).
>

The function where get (or eval) are called from is defined in a
package. The other  functions (the ones with the postfix) are either
in the same package or in the global environment (read from a file). I
think with both solutions (get and eval) and defining the other
functions both ways (in a package and in the global env) I should be
OK, but I probably want to make this explicit.


Thanks,

R.


> > and now define all possible functions as
> >
> > geneSelect.Fratio <- function(x, y, z) {##something}
> > geneSelect.Wilcoxon <- function(x, y, z) {## something else}
> >
> > If I want more geneSelect functions, adding them is simple. And I can
> > even allow the user to pass her/his own functions, with the only
> > restriction that it takes three args, x, y, z, and that the function
> > is to be called: "geneSelect." and a user choosen string. (Yes, I need
> > to make sure no calls to "system", etc, are in the user code, etc,
> > etc, but that is another issue).
>
> [...]
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz



More information about the R-help mailing list