[Rd] UseMethod change; isas-tests; all.equal

John Chambers jmc@research.bell-labs.com
Mon Jan 20 16:18:29 2003


I was a little optimistic that the modified version passed _all_ the
tests.  When I installed the complete change, all the fullcheck tests
passed except two, demos and isas-tests.

There is a tiny difference in the output of the demos test, where the
previous demos.Rout had what looks like an unwanted piece of output,
printing an attribute "legend" after doing 
  symnum(summary(detg.mod, correlation = TRUE)$corr)

There are a slew of differences in the isas-tests output.

There are two issues here, one a real inconsistency from the change in
UseMethod, the other a problem with the isas-tests.

1. Part or all of the changes come from a real example of the behavior I
optimistically called "bizarre":  having a foo.numeric that you DON'T
want to be dispatched on numeric objects.

The example is all.equal.numeric (and .list, .character).  With the
change to UseMethod, this gets dispatched when the first argument to
all.equal is a numeric vector (list, character). So:

R> x <- "abc"
R> y <- as.matrix(x)
R> all.equal(x, y)
[1] TRUE
R> all.equal(y, x)
[1] "Attributes: < Modes: list, NULL >"                                
[2] "Attributes: < Lengths: 1, 0 >"                                    
[3] "Attributes: < names for target but not for current >"             
[4] "Attributes: < Length mismatch: comparison on first 0 components >"
[5] "target is matrix, current is character"                           

The fix seems to be to check is.numeric(current),etc. in each of the
"methods", unless someone has a better suggestion.  An alternative would
renaming all.equal.numeric to all.equalNumeric, etc., but that seems
likely to break somebody's code.

Thoughts??

2.  But the isas-tests seem basically flawed.

Many of the differences in the output come from tests such as
  f <- as.data.frame.POSIXct( x );  all.equal(f, as.data.frame.POSIXct(
f ), tol=0)
This and many more seem as if they should generate TRUE, but they
produce differences & have done for some time (certainly in 1.6.2).  The
change to UseMethod (i.e., to usemethod in objects.c) alters the content
of the reported differences in some cases.se come from tests such as
  f <- as.data.frame.POSIXct( x );  all.equal(f, as.data.frame.POSIXct(
f ), tol=0)
This and many more seem as if they should generate TRUE, but they
produce differences & have done for some time (certainly in 1.6.2).  The
change to UseMethod (i.e., to usemethod in objects.c) alters the content
of the reported differences in some cases.

There is all this output from all.equal tests that "fail".
There are also a number of actual errors generated along the way (these
seem unchanged by the usemethod modification).

These seem to be part of a bunch of tests for idempotent behavior of the
as.* functions--the notion that as.foo(as.foo(x)) and as.foo(x) should
be identical.  But clearly they aren't always.

It's not clear what should be done here.  Does anyone recall how we got
to the current state?  My feeling is that the current setup is
fundamentally bad.  The essence of the desired test would seem to be
something like:
	identical(try(as.foo(as.foo(x))), try(as.foo(x)))
which allows for some of the as.* expressions to fail. Comparing on the
exact output of all.equal when it finds differences has got to be
unstable.

There are some other inconsistencies that point to difficulties with
all.equal.  I don't think one should use all.equal in tests of this
sort, you really want to insist on identical objects.   But should we be
leaving in tests whose result seem to point to bugs?

-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc