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

From: Bill Dunlap <bill_at_insightful.com>
Date: Fri 08 Sep 2006 - 17:05:43 GMT

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



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Sep 09 03:08:32 2006

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 Fri 08 Sep 2006 - 17:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.