One of the advantages of using the S4 method over the simple function R is that the method is strongly typed .
- Having a signature is a protection that methods are not exposed to types that do not meet their signature requirements. Otherwise, an exception.
- ,
.
.
- ( R , S4 )
, ,
show.vector <- function(.object,name,...).object[,name]
setGeneric("returnVector", function(.object,name,...)
standardGeneric("returnVector")
)
setMethod("returnVector", signature(.object="data.frame", name="character"),
def = function(.object, name, ...) show.vector(.object,name,...),
valueClass = "data.frame"
)
, :
show.vector(mtcars,'cyl')
show.vector(mtcars,1:10)
show.vector(mtcars,-1)
:
returnVector(mtcars,'cyl')
returnVector(mtcars,1:10)
returnVector(mtcars,-1)
, , .