[R] methods: Extending classes

Henrik Bengtsson hb at maths.lth.se
Wed Jan 9 23:47:28 CET 2002


Hi (again), let's say I want to create a class Matrix that extends the class
matrix, but I can't get it to work. I define the class as

  > setClass("Matrix", "matrix")
  > getClass("Matrix")

  No Slots, prototype of class "matrix"

  Extends:
  Class "matrix" directly.
  Class "structure" by class "matrix".
  Class "vector" by class "matrix".
  Class "array" by class "matrix".

Creating a default Matrix object works fine:

  > m1 <- new("Matrix")

But, when I try to set its value I get the following error:

  > m3 <- new("Matrix", 1)
  Error in asMethod(object, Class, value) : unused argument(s) ( ...)

or

  > m2 <- new("Matrix", matrix(1))
  Error in asMethod(object, Class, value) : unused argument(s) ( ...)

I also tried to declare a class MyInteger that extends the class integer,
but the same errors:

  > setClass("MyInteger", representation("integer"))
  > i1 <- new("MyInteger")
  > i2 <- new("MyInteger", 3)
  Error in asMethod(object, Class, value) : unused argument(s) ( ...)
  > i3 <- new("MyInteger", as.integer(3))
  Error in asMethod(object, Class, value) : unused argument(s) ( ...)

A bug or me?

Henrik Bengtsson

Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
h b @ m a t h s . l t h . s e
http://www.maths.lth.se/matstat/staff/hb/


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list