[Rd] names function for environments?
haverty.peter at gene.com
Sun Jan 25 21:21:04 CET 2015
The "ls" function wears two hats. It allows users to inspect an
environment interactively and also serves deeper in code as the
accessor for an environment's names/keys. I propose that we separate
these two conflicting goals, keeping ls for interactive use and adding
names for a quick listing of the hash keys. This involves adding two
lines to do_names in attrib.c.
The 'ls' function and its 'objects' synonym appear very frequently in
performance-critical code like base/R/namespace.R and throughout the
methods package. These functions are currently among the major
contributors to execution time in package loading.
This two-line addition to attrib.c gives a significant speedup for
listing an environment's names/keys (2-60X depending on the 'sorted'
argument). It also simplifies the environment API by making it more
like the other basic types. We already have $ and [[ after all.
Rather than sprinkling sorted=FALSE throughout the methods and base
code, let's use names.
Would you be open to this change?
I have submitted a patch and some timings to the bug tracker as
Peter M. Haverty, Ph.D.
phaverty at gene.com
More information about the R-devel