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

From: Ramon Diaz-Uriarte <rdiaz02_at_gmail.com>
Date: Sat 06 Jan 2007 - 19:08:45 GMT

On 1/6/07, Brian Ripley <ripley@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@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

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun Jan 07 06:14:23 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 Jan 2007 - 20:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.