[R] setClass confusion

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jul 4 02:07:06 CEST 2013


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



More information about the R-help mailing list