S4 constructor initialize and prototype
问题 I am trying to build a S4 object by calling the validity method in the constructor. setClass("Person", slot = c(Age = "numeric")) validityPerson<-function(object){ if(object@Age < 0)return("Age cannot be negative") TRUE } setValidity("Person", validityPerson) setMethod("initialize","Person", function(.Object,...){ validObject(.Object) .Object }) This code is problematic because I get new("Person", Age = 12) #Error in if (object@Age < 0) return("Age cannot be negative") : #argument is of