r - methods for an object with length(class)>1 -
this question suggests using methods(class=class(obj))
extract list of methods available object.
if used on object length(class(obj))>1
, leads lots of warnings, e.g.
set.seed(101) <- matrix(rnorm(20), nrow = 10) b <- + rnorm(length(a)) obj <- lm(b ~ a)
gives class(obj)
c("lm","mlm")
; methods(class=class(obj))
gives
(many times)< warning in grep(pattern, all.names, value = true) : argument 'pattern' has length > 1 , first element used
warning in gsub(name, "", s3reg) : argument 'pattern' has length > 1 , first element used
warning in sub(paste0("\.", class, "$"), "", row.names(info)) : argument 'pattern' has length > 1 , first element used
followed results.
it seems (?) applying methods(class=...)
last element of class(obj)
work, i'm interested in alternatives or discussion why (or not) correct ...
to clarify, returned value (preferably unique) character vector, can use if ("foo" %in% allmethods(obj))
test availability of specified method object ...
is you're looking for?
sapply(class(obj), function(x) methods(class = x))
note code below gives error, since argument generic.function
becomes mlm
. must argument class
above.
sapply(class(obj), methods) error in .s3methods(generic.function, class, parent.frame()) : no function 'mlm' visible
Comments
Post a Comment