Hi all, One of the things I find most problematic in R is the partial matching of names in lists. Robert and I have discussed this and we believe that having a mechanism that does not do partial matching would be of significant benefit to R programmers. To that end, I have written a patch that modifies the behavior of "[[" as follows: 1. [[ gains an 'exact' argument with default value NA 2. Behavior of 'exact' argument: exact=NA partial matching is performed as usual, however, a warning will be issued when a partial match occurs. This is the default. exact=TRUE no partial matching is performed. exact=FALSE partial matching is allowed and no warning issued if it occurs. This change has been discussed among R-core members and there appeared to be a general consensus that this approach was a good way to proceed. However, we are interested in other suggestions from the broader R developer community. Some additional rationale for our approach: Lists are used as the underlying data structures in many R programs and in these cases the named elements are not a fixed set of things with a fixed set of names. For these programs, [[ will be used with an argument that gets evaluated at runtime and partial matching here is almost always a disaster. Furthermore, dealing with data that has common prefixes happens often and is not an exceptional circumstance (a precondition for partial matching issues). We have tested a similar patch that simply eliminated partial matching for [[ on all CRAN and Bioconductor packages and did not see any obvious failures. A downside of this approach is that S4 methods on [[ will need to be modified to accommodate the new signature. However, by adding an argument, we are able to move more slowly towards a non-partially matching [[ (eventually, the default could be exact=TRUE, but that is a discussion for another day). + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
On Thu, 17 May 2007, Seth Falcon wrote:> One of the things I find most problematic in R is the partial matching > of names in lists. Robert and I have discussed this and we believe > that having a mechanism that does not do partial matching would be of > significant benefit to R programmers. To that end, I have written a > patch that modifies the behavior of "[[" as follows: > > 1. [[ gains an 'exact' argument with default value NA > > 2. Behavior of 'exact' argument: > > exact=NA > partial matching is performed as usual, however, a warning > will be issued when a partial match occurs. This is the > default. > > exact=TRUE > no partial matching is performed. > > exact=FALSE > partial matching is allowed and no warning issued if it > occurs. > > This change has been discussed among R-core members and there appeared > to be a general consensus that this approach was a good way to > proceed. However, we are interested in other suggestions from the > broader R developer community. > > Some additional rationale for our approach: > > Lists are used as the underlying data structures in many R programs > and in these cases the named elements are not a fixed set of things > with a fixed set of names. For these programs, [[ will be used with > an argument that gets evaluated at runtime and partial matching here > is almost always a disaster. Furthermore, dealing with data that has > common prefixes happens often and is not an exceptional circumstance > (a precondition for partial matching issues).This sounds interesting. Do you intend to leave the $ operator alone, so it will continue to do partial matching? I suspect that that is where the majority of partial matching for list names is done. It might be nice to have an option that made x$partial warn so we would fix code that relied on partial matching, but that is lower priority. ---------------------------------------------------------------------------- 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."
In addition to $ that was mentioned in this thread there is also attr, e.g.> names(attributes(CO2))[1] "names" "row.names" "class" "formula" "outer" "labels" [7] "units"> attr(CO2, "f") # matches "formula"uptake ~ conc | Plant On 5/17/07, Seth Falcon <sfalcon at fhcrc.org> wrote:> Hi all, > > One of the things I find most problematic in R is the partial matching > of names in lists. Robert and I have discussed this and we believe > that having a mechanism that does not do partial matching would be of > significant benefit to R programmers. To that end, I have written a > patch that modifies the behavior of "[[" as follows: > > 1. [[ gains an 'exact' argument with default value NA > > 2. Behavior of 'exact' argument: > > exact=NA > partial matching is performed as usual, however, a warning > will be issued when a partial match occurs. This is the > default. > > exact=TRUE > no partial matching is performed. > > exact=FALSE > partial matching is allowed and no warning issued if it > occurs. > > This change has been discussed among R-core members and there appeared > to be a general consensus that this approach was a good way to > proceed. However, we are interested in other suggestions from the > broader R developer community. > > Some additional rationale for our approach: > > Lists are used as the underlying data structures in many R programs > and in these cases the named elements are not a fixed set of things > with a fixed set of names. For these programs, [[ will be used with > an argument that gets evaluated at runtime and partial matching here > is almost always a disaster. Furthermore, dealing with data that has > common prefixes happens often and is not an exceptional circumstance > (a precondition for partial matching issues). > > We have tested a similar patch that simply eliminated partial matching > for [[ on all CRAN and Bioconductor packages and did not see any > obvious failures. > > A downside of this approach is that S4 methods on [[ will need to be > modified to accommodate the new signature. However, by adding an > argument, we are able to move more slowly towards a non-partially > matching [[ (eventually, the default could be exact=TRUE, but that is > a discussion for another day). > > > + seth > > -- > Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center > http://bioconductor.org > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Hi again, Robert has committed the proposed patch to R-devel. So [[ now has an 'exact' argument and the behavior is as described: Seth Falcon <sfalcon at fhcrc.org> writes:> 1. [[ gains an 'exact' argument with default value NA > > 2. Behavior of 'exact' argument: > > exact=NA > partial matching is performed as usual, however, a warning > will be issued when a partial match occurs. This is the > default. > > exact=TRUE > no partial matching is performed. > > exact=FALSE > partial matching is allowed and no warning issued if it > occurs. >+ seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org