No definition for classes from another package

Viewed 35

I hit a weird problem in a large codebase and cannot really figure out where to start debugging. Long story short, there is third party package, we'll call foo with DESCRIPTION

Package: foo
Type: Package
Title: Foo
Version: 0.1.0
Author: Foo Dev
Maintainer: Foo Dev <foo@foo>
Description: Does foo
License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2

NAMESPACE

# Generated by roxygen2: do not edit by hand

exportClasses(FooA)
exportClasses(FooB)

and code

#' @export
setClass("FooA", representation())

#' @export
setClass("FooB", representation())

I use this package in another package, let's call it bar,

Package: bar
Type: Package
Title: Bar
Version: 0.1.0
Author: Bar Dev
Maintainer: Bar Dev <bar@bar>
Description: Does bar
License: BSD
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
Imports:
  foo

where I define following generics

#' @name bar
#' @rdname bar
setGeneric(
  "bar",
  function(fooa, foob) { standardGeneric("bar") })


#' bar
#'
#' @param fooa FooA
#' @param foob FooB
#' @name bar
#' @rdname bar
#' @aliases bar,FooA,FooB-method
#' @export
setMethod(
  "bar",
  signature(fooa = "FooA", foob = "FooB"),
  function(fooa, foob) {

  }
)

I check the package and boom, I get:

Found the following significant warnings:
  Warning: in method for ‘bar’ with signature ‘fooa="FooA",foob="FooB"’: no definition for classes “FooA”, “FooB”

If I change signature to for example

  signature(fooa = "FooA", foob = "ANY"),

or

  signature(fooa = "ANY", foob = "FooB"),

things run smoothly. I can also define all kinds of generics, as long as they dispatch on only one of these classes at the time.

I use R version 4.1.1 (2021-08-10), if that's relevant here.

What is going on here?

0 Answers
Related