Skip to content

[R-pkg-devel] Define S4 method for generic in other package

3 messages · Thierry Onkelinx, Duncan Murdoch, Hadley Wickham

#
Dear all,

I'm trying to define a new S4 method for a generics defined in an
other package. Here is my attempt, but that isn't working.

bar <- function(a, b) is defined as generic and S4 method in the package foo

#' @importFrom foo bar
#' @importMethodsFrom foo bar
setMethod(
  f = "bar",
  signature = signature(A = "myClass"),
  definition = function(
    a,
    b
  ){
    bar(
      a = myClass at A,
      b = myClass at B
    )
  }
)

When I build my package I get the error "no existing definition for
function 'bar'".

Any suggestions?

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
#
On 28/08/2015 4:23 AM, Thierry Onkelinx wrote:
I'd advise against using Roxygen2 declarations.  They might be right,
they might not, but you limit the number of people who can answer your
question to those who know *both* Roxygen2 *and* S4 details.

The Writing R Extensions manual describes the NAMESPACE requirements to
do what you want pretty clearly, but I have no idea if the declarations
above satisfy them.

Duncan Murdoch
3 days later
#
I'd recommend creating a minimal package that illustrates the problem
using an existing S4 generic in a base package (e.g. stats4::AIC).
That makes it easier to figure out what's gone wrong.

It's unlikely to be a roxygen2 problem since the translation from
@importFrom foo bar (etc) to importFrom(foo, bar) is quite
straightforward.

Hadley

On Fri, Aug 28, 2015 at 3:23 AM, Thierry Onkelinx
<thierry.onkelinx at inbo.be> wrote: