[Rd] (PR#9202) Re: Bugs with partial name matching

Bill Dunlap bill at insightful.com
Fri Sep 8 19:05:43 CEST 2006


> >  I can get the
> > desired single element match using the convoluted syntax D["ABC"]
> > [[1]] and perform partial replacement operations on a new column.
> > However, it would be nice to have single element access operator that
> > does exact matching.
>
> It wouldn't fix the bug, and we are running low on symbols that could be
> used.

SV4 and Splus have a function called elNamed() (and a corresponding
elNamed<-) that does exact matching.  E.g.,

> zlist<-list(abc=1, xyz=2)
> elNamed(zlist, "a")
NULL
> elNamed(zlist, "a", mustfind=TRUE) # error should say "element", not "slot"
Problem in elNamed(zlist, "a", mustfind = TRUE): Failed to find required slot "a"
Use traceback() to see the call stack
> elNamed(zlist, "abc")
[1] 1
> elNamed(zlist, "ab") <- 3
> dput(zlist)
list("abc" = 1
, "xyz" = 2
, "ab" = 3
)

It works on lists and atomic vectors and I think it
is not intended to be a generic function.  There is
a similar el(x, i) function for numeric subsetting
that is not intended to be generic (that is for
speed and safety when writing methods for [).

Its only documentation is some self-doc:

> elNamed
# extract or (when used on left of assignment) replace the element of `object' associated
# with `name'.  Differs from `$' in using only exact matching. Set `mustfind=T' if you
# want an error to occur when there is no such named element. NOT to be used for slots.
function(object, name, mustfind = F)
.Internal(elNamed(object, name, mustfind), "S_el_named", T, 0)

It isn't used much and has some surprises.  E.g.,
   elNamed(zlist, "ab")<-NULL
sets $ab to NULL; it doesn't remove it as ab$ab would.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."




More information about the R-devel mailing list