Dear R People: I am experimenting with S4 classes and methods but am having trouble with setting up a class. Here is an example:> buzz <- setClass("buzz",slots=c(x="matrix"),+ validity <- function(object) { + if(is.matrix(object)==FALSE)stop("Input must be a matrix") + TRUE + }) Error in setClass("buzz", slots = c(x = "matrix"), validity <- function(object) { : Argument "representation" cannot be used if argument "slots" is supplied>I know that there is something simple that I'm just not seeing. This is R-3.0.1 for Windows. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess@gmail.com [[alternative HTML version deleted]]
On 13-07-03 7:54 PM, Erin Hodgess wrote:> Dear R People: > > > I am experimenting with S4 classes and methods but am having trouble with > setting up a class. > > Here is an example: > >> buzz <- setClass("buzz",slots=c(x="matrix"), > + validity <- function(object) { > + if(is.matrix(object)==FALSE)stop("Input must be a matrix") > + TRUE > + }) > Error in setClass("buzz", slots = c(x = "matrix"), validity <- > function(object) { : > Argument "representation" cannot be used if argument "slots" is supplied >> > > I know that there is something simple that I'm just not seeing.Since you used <-, your third argument uses the positional name "representation", not "validity", which is presumably what you intended. Duncan Murdoch
On Jul 3, 2013, at 4:54 PM, Erin Hodgess wrote:> Dear R People: > > > I am experimenting with S4 classes and methods but am having trouble with > setting up a class. > > Here is an example: > >> buzz <- setClass("buzz",slots=c(x="matrix"), > + validity <- function(object) { > + if(is.matrix(object)==FALSE)stop("Input must be a matrix") > + TRUE > + }) > Error in setClass("buzz", slots = c(x = "matrix"), validity <- > function(object) { : > Argument "representation" cannot be used if argument "slots" is supplied >> > > I know that there is something simple that I'm just not seeing.If you take the validity argument out it doesnot throw an error and the help page for setClass refers you to ?validObject for details.> > This is R-3.0.1 for Windows. > Thanks for any help. > > Sincerely, > Erin >David Winsemius Alameda, CA, USA