Skip to content
Prev 24786 / 63424 Next

Signature of '!' (was Problem with R-2.5.0 patched and Matrix package)

Yes, it works in the release.

The essence of the problem is that Matrix defines an S4 method for '!' 
with dispatch on 'e1', but the documentation for '!' (and many S3 methods) 
says the argument is 'x'.  As '!' is a primitive the argument matching of 
the base function might be expected to be positional only, but that is not 
what happens with methods.

This needs some juggling, and clearly two patches in R-patched have 
conflicted.  I've reverted one of them and this seems to work again (but 
something else no longer works: see below).

Longer term, I don't know what the right way forward is.  Consider
[1] "foo"
[1] "!"
[1] NA
[1] NA
Error in !x : unused argument(s) (x = TRUE)
[1] NA

which is not what the reader of the help for '!' might expect.  But it 
gets worse:
(and there are several S3 methods like that in CRAN packages)
[1] NA
[1] NA
Error in !x2 : unused argument(s) (x = TRUE)
Error in `!.bar`(e1 = x2) : unused argument(s) (e1 = TRUE)

whereas `!`(x=x2) does work if you do not set an S4 method on '!'.
This may seem artificial, but this sort of thing can happen if you use 
operators as functions in lapply().

Since there are in packages S3 methods on 'x' and S4 methods on 'e1', we 
have a conflict.

My gut feeling is that the inconsistency is the S4 signature, and 
certainly that seems the easier one to change.  I knew about this because 
the behind-the-scenes S4 generics in R-devel are auto-generated from the 
descriptions of the primitives.  Now in 2.5.0 you will see
function (x)  .Primitive("!")

and hence there needed to be an exclusion list (which now includes '!' and 
'c')  to have Matrix work in R-devel.  An alternative is to make the 
internal method dispatch on operators ignore the argument names.

(I can guess where this comes from.  '!' is a member of the S3 Ops group, 
and as part of a group method you define Ops(e1, e2) and ignore e2.  But 
'!' is not part of the S4 group generic Logic in R.)

Thanks for the report.
On Thu, 26 Apr 2007, Seth Falcon wrote: