From bill at insightful.com  Fri Sep  8 19:05:43 2006
From: bill at insightful.com (Bill Dunlap)
Date: Fri, 8 Sep 2006 10:05:43 -0700 (PDT)
Subject: [Rd] (PR#9202) Re: Bugs with partial name matching
In-Reply-To: <Pine.LNX.4.64.0609080916200.24159@homer23.u.washington.edu>
References: <20060905014002.634C928F8E@slim.kubism.ku.dk>
	<Pine.LNX.4.64.0609051507530.17674@homer23.u.washington.edu>
	<Pine.LNX.4.64.0609051542310.17674@homer23.u.washington.edu>
	<69C0202D-ED5A-495A-9F38-FD2F7F132C29@uic.edu>
	<Pine.LNX.4.64.0609080916200.24159@homer23.u.washington.edu>
Message-ID: <Pine.GSO.4.56.0609080954590.19218@durian.statsci.com>

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




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