timothy.s.lau
timothy.s.lau

Reputation: 1101

How to call a specific S4 method in R

I was working in the mirt package in R and noticed that I couldn't use mirt:: or mirt::: to call the coef or residuals functions. From what I can tell this is a S3 to S4 difference (magic fingers & hand waving).

Which brings me to the question, how do you call a specific R function within it's package when it's coded in S4?

Upvotes: 1

Views: 837

Answers (1)

Martin Morgan
Martin Morgan

Reputation: 46866

After

> library(mirt)
Loading required package: stats4
Loading required package: lattice

I see

> methods(coef)
 [1] coef,ANY-method                coef,DiscreteClass-method     
 [3] coef,MixedClass-method         coef,mle-method               
 [5] coef,MultipleGroupClass-method coef,SingleGroupClass-method  
 [7] coef,summary.mle-method        coef.aov*                     
 [9] coef.Arima*                    coef.default*                 
[11] coef.listof*                   coef.nls*                     
see '?methods' for accessing help and source code

I guess you have an instance of one of the classes, e.g., 'DiscreteClass'. You can select the method with

selectMethod("coef", signature="DiscreteClass")

or maybe more naturally

selectMethod("coef", class(obj))

where obj is an instance of the object you're interested in. But you shouldn't have to call a specific method; this should be taken care of -- what's the problem you're actually experiencing.

Upvotes: 2

Related Questions