Given a function class, find correspoding S4 method

method_from_call(call, env = parent.frame())

Arguments

call

unquoted function call

env

environment in which to look for function definition

Examples

library(stats4)

# From example(mle)
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
nLL <- function(lambda) -sum(dpois(y, lambda, log = TRUE))
fit <- mle(nLL, start = list(lambda = 5), nobs = length(y))

method_from_call(summary(fit))
#> new("MethodDefinition", .Data = function (object, ...) 
#> {
#>     cmat <- cbind(Estimate = object@coef, `Std. Error` = sqrt(diag(object@vcov)))
#>     m2logL <- 2 * object@min
#>     new("summary.mle", call = object@call, coef = cmat, m2logL = m2logL)
#> }, target = new("signature", .Data = "mle", names = "object", 
#>     package = "stats4"), defined = new("signature", .Data = "mle", 
#>     names = "object", package = "stats4"), generic = "summary")
#> <bytecode: 0x58b585edcd28>
#> <environment: namespace:stats4>
#> attr(,"target")
#> An object of class “signature”
#> object 
#>  "mle" 
#> attr(,"defined")
#> An object of class “signature”
#> object 
#>  "mle" 
#> attr(,"generic")
#> [1] "summary"
#> attr(,"generic")attr(,"package")
#> [1] "base"
#> attr(,"class")
#> [1] "MethodDefinition"
#> attr(,"class")attr(,"package")
#> [1] "methods"
method_from_call(coef(fit))
#> new("MethodDefinition", .Data = function (object, ...) 
#> {
#>     .local <- function (object) 
#>     object@fullcoef
#>     .local(object, ...)
#> }, target = new("signature", .Data = "mle", names = "object", 
#>     package = "stats4"), defined = new("signature", .Data = "mle", 
#>     names = "object", package = "stats4"), generic = "coef")
#> <bytecode: 0x58b57c05aa70>
#> <environment: namespace:stats4>
#> attr(,"target")
#> An object of class “signature”
#> object 
#>  "mle" 
#> attr(,"defined")
#> An object of class “signature”
#> object 
#>  "mle" 
#> attr(,"generic")
#> [1] "coef"
#> attr(,"generic")attr(,"package")
#> [1] "stats"
#> attr(,"class")
#> [1] "MethodDefinition"
#> attr(,"class")attr(,"package")
#> [1] "methods"
method_from_call(length(fit))
#> function (x)  .Primitive("length")