Re: [Rd] setMethod("Logic", ...)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 04 Sep 2006 - 09:49:33 GMT

On Mon, 4 Sep 2006, Robin Hankin wrote:

> Professor Ripley
>
> thank you for this (and indeed thank you for solving my earlier
> problem on octonions).
>
> I still don't know how to force logic operations on brob objects to give an
> error.

I found this in the methods sources

    ## R does not currently do the Logic group (! & |)
    ## A strange group, since the argument lists are different.  But
    ## perhaps we'll add it sometime.

(Not sure about the comment: there are unary and binary operators in Arith.)

It looks to me as if you can work around this by defining S3 methods for the class, if that is all you want to do.

setClass("foo", representation="numeric") x <- new("foo", pi)
> !x

[1] FALSE
> "!.foo" <- function(x) stop("not supported")
> !x

Error in "!.foo"(x) : not supported

> 06, at 16:45, Prof Brian Ripley wrote:
>
> >Accordng to the S4groupGeneric page, there is no such group.
> >
> >My guess as to why:
> >
> >Those operators are not S3 generic in R, and S4 dispatch is piggy-backed
> >on S3 dispatch (not necessarily, but for convenience).

I was wrong here.

> I have been trying to use the example on p119 of S Programming as
> a template:
>
>
> setClass("brob",
> representation = representation(x="numeric",positive="logical"),
> prototype = list(x=numeric(),positive=logical())
> )
>
>
> .logicBrob <- function(e1,e2){
> stop("No logic currently implemented for Brobdingnagian numbers")
> }
>
>
> setMethod("Logic",signature(e1="brob"), .logicBrob)
> setMethod("Logic",signature(e2="brob"), .logicBrob)
>
>
>
> but this does not work as desired (setMethod() gives an error). I want,
> for example,
>
> !new("brob", x=1:10,positive=rep(T,10))
>
> to call .logicBrob() and report an error.
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
> tel 023-8059-7743
>

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon Sep 04 19:59:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 06 Sep 2006 - 11:39:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.