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

From: Brian Ripley <>
Date: Sat 06 Jan 2007 - 15:30:24 GMT

On Sat, 6 Jan 2007, Ramon Diaz-Uriarte wrote:

> Dear Greg,
> On 1/5/07, Greg Snow <> wrote:
>> Ramon,
>> I prefer to use the list method for this type of thing, here are a couple of reasons why (maybe you are more organized than me and would never do some of the stupid things that I have, so these don't apply to you, but you can see that the general suggestion applys to some of the rest of us).
> Those suggestions do apply to me of course (no claim to being
> organized nor beyond idiocy here). And actually the suggestions on
> this thread are being very useful. I think, though, that I was not
> very clear on the context and my examples were too dumbed down. So
> I'll try to give more detail (nothing here is secret, I am just trying
> not to bore people).
> The code is part of a web-based application, so there is no
> interactive user. The R code is passed the arguments (and optional
> user functions) from the CGI.
> There is one "core" function (call it cvFunct) that, among other
> things, does cross-validation. So this is one way to do things:
> 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 = "."))

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).

> 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,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun Jan 07 03:20:13 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 - 19:32:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.