[Rd] confusion over S3/S4 importing

From: Ben Bolker <bbolker_at_gmail.com>
Date: Mon, 30 Jul 2012 10:12:01 -0400

  Can anyone help me figure out the right way to import a method that is defined as S3 in one package and S4 in another?

  Specifically:

 profile() is defined as an S3 method in the stats package:

function (fitted, ...)
UseMethod("profile")
<bytecode: 0xa4cd6e8>
<environment: namespace:stats>

 In stats4 it is defined as an S4 method:

 stats4:::profile
standardGeneric for "profile" defined from package "stats"

function (fitted, ...)
standardGeneric("profile")
<environment: 0xa59a364>

   In the bbmle package I want to define it as an S4 method:

  setMethod("profile", "mle2", function (...) {...})

  In the NAMESPACE file for bbmle I have

 importFrom(stats4,profile)

  However, in R 2.14.2 (which is I am currently trying to fix: I would like to try to allow for backward compatibility), I get

library(bbmle)
example(mle2) ## to create some fitted objects
profile(fit)

Error in UseMethod("profile") :
  no applicable method for 'profile' applied to an object of class "mle2"

 whereas stats4::profile(fit) works fine.

  I would have thought that importFrom() would allow package code to find the 'stats4' version of profile (and coef) before it found the 'stats' versions , but that doesn't seem to be the case.

  Just for kicks I tried

import(stats4)

  which leads to warning messages but no improvements.

If I add an explicit Depends: on stats4 that fixes the problem. I may be forced to do that, but I thought it was supposed to be a last resort and that I was *supposed* to be able to fix my problems by proper use of imports.

  Any insights?

  thanks
    Ben Bolker



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 30 Jul 2012 - 14:18:44 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 01 Aug 2012 - 15:50:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive