On 02/14/2011 11:54 PM, robin hankin wrote:> 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?
Oarray is an S3 class, so
setOldClass("Oarray")
before defining methods on the class.
Hope that helps,
Martin
> 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'?
>
>
>
>
>
>
--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
Location: M1-B861
Telephone: 206 667-2793