[Rd] Signature of '!' (was Problem with R-2.5.0 patched and Matrix package)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Apr 30 12:52:23 CEST 2007
I think I have a workaround for this in R-devel now, but obviously it will
be better to change Matrix in due course.
I believe this requires Matrix to be re-installed (again) under R-devel.
On Sat, 28 Apr 2007, Martin Maechler wrote:
>>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk>
>>>>>> on Thu, 26 Apr 2007 22:57:11 +0100 (BST) writes:
> BDR> Yes, it works in the release. The essence of the
> BDR> problem is that Matrix defines an S4 method for '!'
> BDR> with dispatch on 'e1', but the documentation for '!'
> BDR> (and many S3 methods) says the argument is 'x'. As '!'
> BDR> is a primitive the argument matching of the base
> BDR> function might be expected to be positional only, but
> BDR> that is not what happens with methods.
> BDR> This needs some juggling, and clearly two patches in
> BDR> R-patched have conflicted. I've reverted one of them
> BDR> and this seems to work again (but something else no
> BDR> longer works: see below).
> BDR> Longer term, I don't know what the right way forward
> BDR> is. Consider
> >> setClass("foo", "logical")
> BDR>  "foo"
> >> setMethod("!", "foo", function(e1) NA)
> BDR>  "!"
> >> x <- new("foo", TRUE) !x
> BDR>  NA
> >> `!`(x)
> BDR>  NA
> >> `!`(x=x)
> BDR> Error in !x : unused argument(s) (x = TRUE)
> >> `!`(e1=x)
> BDR>  NA
> BDR> which is not what the reader of the help for '!' might
> BDR> expect. But it gets worse:
> >> x2 <- structure(TRUE, class="bar") `!.bar` <- function(x)
> >> NA
> BDR> (and there are several S3 methods like that in CRAN
> BDR> packages)
> >> !x2
> BDR>  NA
> >> `!`(x2)
> BDR>  NA
> >> `!`(x=x2)
> BDR> Error in !x2 : unused argument(s) (x = TRUE)
> >> `!`(e1=x2)
> BDR> Error in `!.bar`(e1 = x2) : unused argument(s) (e1 =
> BDR> TRUE)
> BDR> whereas `!`(x=x2) does work if you do not set an S4
> BDR> method on '!'. This may seem artificial, but this sort
> BDR> of thing can happen if you use operators as functions
> BDR> in lapply().
> BDR> Since there are in packages S3 methods on 'x' and S4
> BDR> methods on 'e1', we have a conflict.
> BDR> My gut feeling is that the inconsistency is the S4
> BDR> signature, and certainly that seems the easier one to
> BDR> change. I knew about this because the
> BDR> behind-the-scenes S4 generics in R-devel are
> BDR> auto-generated from the descriptions of the primitives.
> BDR> Now in 2.5.0 you will see
> >> `!`
> BDR> function (x) .Primitive("!")
> BDR> and hence there needed to be an exclusion list (which
> BDR> now includes '!' and 'c') to have Matrix work in
> BDR> R-devel. An alternative is to make the internal method
> BDR> dispatch on operators ignore the argument names.
> BDR> (I can guess where this comes from. '!' is a member of
> BDR> the S3 Ops group, and as part of a group method you
> BDR> define Ops(e1, e2) and ignore e2. But '!' is not part
> BDR> of the S4 group generic Logic in R.)
> Yes, indeed (and that was made so very consciously after
> discussion between John and me (and maybe more people)) in
> order to at least keep the signature precise for the (S4)Logic group.
> I agree with you (Brian) that the inconsistency between
> '(x)' and '(e1)' is ugly and I agree that we
> make the signature into '(x)' and we (I) have to change Matrix
> If possible (easily enough), we should try to keep 'e1' working
> in setMethod("!", .) with a deprecation warning
> BDR> On Thu, 26 Apr 2007, Seth Falcon wrote:
> >> Hi,
> >> Using latest R 2.5.0 Patched, I'm unable to install the
> >> Matrix package from cran.fhcrc.org.
> >> I get:
> >> Creating a new generic function for "isSymmetric" in
> >> "Matrix" Creating a new generic function for "unname" in
> >> "Matrix" Error in conformMethod(signature, mnames,
> >> fnames, f) : In method for function "!": formal arguments
> >> omitted in the method definition cannot be in the
> >> signature (x = "Matrix") Error: unable to load R code in
> >> package 'Matrix' Execution halted ERROR: lazy loading
> >> failed for package 'Matrix' ** Removing
> >> '/home/sfalcon/RLIBS/2.5/Matrix' ** Restoring previous
> >> '/home/sfalcon/RLIBS/2.5/Matrix'
> >> The downloaded packages are in
> >> /tmp/RtmpcEQJjw/downloaded_packages Warning message:
> >> installation of package 'Matrix' had non-zero exit status
> >> in: install.packages(pkgs = pkgs, repos = repos,
> >> dependencies = dependencies,
> >> I don't have this problem when using a recent R-devel.
> >> And I'm guessing that Matrix works with the release, but
> >> haven't had time to check this.
> >> + seth
> BDR> -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of
> BDR> Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> BDR> University of Oxford, Tel: +44 1865 272861 (self) 1
> BDR> South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG,
> BDR> UK Fax: +44 1865 272595
> BDR> ______________________________________________
> BDR> R-devel at r-project.org mailing list
> BDR> https://stat.ethz.ch/mailman/listinfo/r-devel
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel