[Rd] S4 problems
robin hankin
hankin.robin at gmail.com
Tue Feb 15 08:54:55 CET 2011
Hello everybody
[R-2.12.1]
I am having difficulty dealing with Oarray objects.
I have a generic function, call it foo(), and I wish
to define a method for Oarray objects.
I do not have or want a method for regular arrays [actually,
I want to coerce to an Oarray, and give a warning].
But setMethod() does not behave as desired, giving
an error message when I try to define a method for
Oarray objects.
Also, if I define a method for array objects, this does not
give an error message, but neither does it behave as desired,
as the method is not found when passing an Oarray object
to foo().
LE110:~/packages% R --vanilla --quiet
> library(Oarray)
> setGeneric("foo",function(x){standardGeneric("foo")})
[1] "foo"
> setMethod("foo","Oarray",function(x){x})
in method for ‘foo’ with signature ‘"Oarray"’: no definition for class "Oarray"
[1] "foo"
> setMethod("foo","array",function(x){x})
[1] "foo"
> a <- Oarray(0,2:3)
> is.array(a)
[1] TRUE
> foo(a)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "foo", for signature "Oarray"
Three questions:
Why does the first call to setMethod() give an error message?
Why does (a) not find the method defined for arrays, even though 'a'
is an array?
How can I make "foo(a)" behave as desired when 'a' is an object of
class 'Oarray'?
--
Robin Hankin
Uncertainty Analyst
hankin.robin at gmail.com
More information about the R-devel
mailing list