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

Peter Haverty haverty.peter at gene.com
Fri Jan 9 20:06:28 CET 2015


Here are some quick measurements of Martin's accomplishment with "get0":

In loading the package GenomicRanges, 30K calls to "exists" have been
skipped.  (However 99K still remain!)
Overall, the current usage of "get0" seems to save us 10% in package
loading time (no error bars on that measurement).
microbenchmark says that

env = asNamespace("base"); get0("match", env)

is a 6X speedup over the same call to "get", which is pretty neat by
itself.  It might be good to just generally use get0.
Unless of course, when one really doesn't need any "exists" checking and
NULL results are fine, then the .Primitive "[[" is 30X faster than "get".
Thanks everyone for your thoughts, code and time on this topic!





Pete

____________________
Peter M. Haverty, Ph.D.
Genentech, Inc.
phaverty at gene.com

On Fri, Jan 9, 2015 at 7:37 AM, Martin Maechler <maechler at stat.math.ethz.ch>
wrote:

> >>>>> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list