cberry@tajo.ucsd.edu
2000-Sep-29 21:18 UTC
[Rd] all.equal.list() sometimes fails with unnamed and named components (PR#674)
examples: 1) Fails to report that components 2 and 3 differ all.equal(list(1,2,3,zap=1),list(1,3,4,zap=2)) [1] "Component zap: Mean relative difference: 1 2) Incorrectly asserts all are equal when components 2 and 3 differ> all.equal(list(1,2,3,zap=1),list(1,3,4,zap=1))[1] TRUE 3) Removing named component reveals differences:> all.equal(list(1,2,3,1),list(1,3,4,1))[1] "Component 2: Mean relative difference: 0.5" [2] "Component 3: Mean relative difference: 0.3333333" 4) Unequal first component reveals differences> all.equal(list(2,2,3,zap=1),list(1,3,4,zap=1))[1] "Component : Mean relative difference: 0.5" [2] "Component : Mean relative difference: 0.5" [3] "Component : Mean relative difference: 0.5"> all.equal(list(2,2,3,zap=1),list(1,3,4,zap=2))[1] "Component : Mean relative difference: 0.5" [2] "Component : Mean relative difference: 0.5" [3] "Component : Mean relative difference: 0.5" [4] "Component zap: Mean relative difference: 1">5) Second component IS equal, but:> all.equal(list(2,2,3,zap=1),list(1,2,4,zap=2))[1] "Component : Mean relative difference: 0.5" [2] "Component : Mean relative difference: 0.5" [3] "Component : Mean relative difference: 0.5" [4] "Component zap: Mean relative difference: 1" --please do not edit the information below-- Version: platform = sparc-sun-solaris2.7 arch = sparc os = solaris2.7 system = sparc, solaris2.7 status = major = 1 minor = 1.0 year = 2000 month = June day = 15 language = R Search Path: .GlobalEnv, Autoloads, package:base Chuck Berry -- Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry@tajo.ucsd.edu UC San Diego http://hacuna.ucsd.edu/members/ccb.html La Jolla, San Diego 92093-0645 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kurt Hornik
2000-Oct-03 15:40 UTC
[Rd] all.equal.list() sometimes fails with unnamed and named components (PR#674)
>>>>> cberry writes:> examples:> 1) Fails to report that components 2 and 3 differ> all.equal(list(1,2,3,zap=1),list(1,3,4,zap=2)) > [1] "Component zap: Mean relative difference: 1> 2) Incorrectly asserts all are equal when components 2 and 3 differ>> all.equal(list(1,2,3,zap=1),list(1,3,4,zap=1)) > [1] TRUE> 3) Removing named component reveals differences:>> all.equal(list(1,2,3,1),list(1,3,4,1)) > [1] "Component 2: Mean relative difference: 0.5" > [2] "Component 3: Mean relative difference: 0.3333333"> 4) Unequal first component reveals differences>> all.equal(list(2,2,3,zap=1),list(1,3,4,zap=1)) > [1] "Component : Mean relative difference: 0.5" > [2] "Component : Mean relative difference: 0.5" > [3] "Component : Mean relative difference: 0.5" >> all.equal(list(2,2,3,zap=1),list(1,3,4,zap=2)) > [1] "Component : Mean relative difference: 0.5" > [2] "Component : Mean relative difference: 0.5" > [3] "Component : Mean relative difference: 0.5" > [4] "Component zap: Mean relative difference: 1" >>> 5) Second component IS equal, but:>> all.equal(list(2,2,3,zap=1),list(1,2,4,zap=2)) > [1] "Component : Mean relative difference: 0.5" > [2] "Component : Mean relative difference: 0.5" > [3] "Component : Mean relative difference: 0.5" > [4] "Component zap: Mean relative difference: 1"> --please do not edit the information below--> Version: > platform = sparc-sun-solaris2.7 > arch = sparc > os = solaris2.7 > system = sparc, solaris2.7 > status = > major = 1 > minor = 1.0 > year = 2000 > month = June > day = 15 > language = R> Search Path: > .GlobalEnv, Autoloads, package:base> Chuck BerryI think the above happens because all.equal.list() is broken. The fix is not entirely clear, because I am not sure what we really want. Anyway, in all of the above examples we compare lists which are named in the sense that names() is not NULL, but not ``fully'' named in the sense that any(nchar(names()) == NULL) is TRUE. In this case, iseq gets set to nt[c.in.t] which in the above example gives Browse[1]> nt[c.in.t] [1] "" "" "" "zap" Hence in the for(i in iseq) loop we do three comparisons of the first component, due to subscripting with "". The obvious idea is that we must use positional indices where we do not have named ones. Now for the problem I see in the current logic. We currently do if both lists are named (at least partially) then ... else fi Maybe we should change this as follows: if either of the two lists has names, work though the named components. Warn about the ones not present in both. Compare the ones present in both. Then get rid of all named components and compare what is left in positional order. As I said, I am not sure that this is really what we want. Comments? -k -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
2000-Oct-03 16:26 UTC
[Rd] all.equal.list() sometimes fails with unnamed and named components (PR#674)
> To: Kurt.Hornik@ci.tuwien.ac.at > Cc: cberry@tajo.ucsd.edu, r-devel@stat.math.ethz.ch > Subject: Re: [Rd] all.equal.list() sometimes fails with unnamed and namedcomponents (PR#674)> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> > Date: 03 Oct 2000 18:05:50 +0200 > > Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes: > > > Maybe we should change this as follows: if either of the two lists has > > names, work though the named components. Warn about the ones not > > present in both. Compare the ones present in both. Then get rid of all > > named components and compare what is left in positional order. > > > > As I said, I am not sure that this is really what we want. > > > > Comments? > > I think you might be right, and also that this is an easy thing to > implement. Then we'd have > > all.equal(list(a=1,b=2,3,4),list(3,b=2,4,a=1)) == TRUE > > Right?Probably not. Lists do have orderings: they are not sets but generic vectors.> However, BigBrother has > > > all.equal(list(a=1,b=2,3,4),list(3,b=2,4,a=1)) > [1] "Names: 2 string mismatches" > attr(, "continue"): > [1] T > > > all.equal(list(a=1,b=2,3,4), list(a=1,b=2,4,3)) > [1] TThat's not what current versions of S-PLUS give, as one might hope.> ..which does look like a "compatible bug" > > Hmm. Maybe one wants positional matching in any case? But then, what > is the named-component extraction about??I think that both the names and components should match exactly (the components recursively). Unfortunately the named-component extraction is partial matching (at least, sometimes) so the ordering of the names always matters. (There's an S/R difference here I keep forgetting to write down. I think it is x <- list(aa=1, bb=2) x["a"] which gives in S $aa: [1] 1 and in R $"NA" NULL so S always partial matches, but R does not always.) -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._