[Rd] RFC: getifexists() {was [Bug 16065] "exists" ...}

Martin Maechler maechler at stat.math.ethz.ch
Fri Jan 9 16:37:43 CET 2015


>>>>> Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Fri, 9 Jan 2015 14:00:38 +0100 writes:

>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>>     on Thu, 8 Jan 2015 14:02:26 -0800 writes:

    >> On Thu, Jan 8, 2015 at 11:57 AM, <luke-tierney at uiowa.edu> wrote:
    >>> On Thu, 8 Jan 2015, Michael Lawrence wrote:
    >>> 
    >>> If we do add an argument to get(), then it should be named consistently
    >>>> with the ifnotfound argument of mget(). 

You are right... I forgot to say so earlier in the thread.

The definition now is

get0 <- function (x, envir = pos.to.env(-1L), mode = "any", inherits = TRUE,
                  ifnotfound = NULL)
    .Internal(get0(x, envir, mode, inherits, ifnotfound))



    >>>> As mentioned, the possibility of a
    >>>> NULL value is problematic. One solution is a sentinel value that indicates
    >>>> an unbound value (like R_UnboundValue).
    >>>> 
    >>> 
    >>> A null default is fine -- it's a default; if it isn't right for a
    >>> particular case you can provide something else.
    >>> 

    [..................]

    >>> Adding getIfExists, or .get, or get0, or whatever seems fine. Adding
    >>> an argument to get() with missing giving current behavior may be OK
    >>> too. Rewriting exists and get as .Primitives may be sufficient though.

    > Thank you, Luke.  Given that, Duncan's and the other inputs,
    > I think we should go for a new function -- .Internal() for now.

    > To Pete's point about arguments, I did drop 'frame' on purpose 
    > and indeed we could try to do away with 'where/pos' as well and
    > have the environment only specified by 'envir'.

    > Name: I like  get0() for its brevity and prefer it to .get().

    > Let me expose my current implementation on R-devel ... and start
    > using it in the 'methods' package so we (Pete H. :-) can start
    > measuring its impact.

I have now committed  get0() to R-devel  (svn rev 67386) 

which is already using it in quite a few places:
in 'base', notably in base/R/namespace.R   where it may speedup, also
in 'methods' in quite a few places also in the hope of some S4
speedup.

{{Now I feel having deserved some weekend break ...}}

Martin



More information about the R-devel mailing list