Heisenberg
Heisenberg

Reputation: 8806

How to make S4 class from another package available to my package?

I'm following Hadley's guide to implement a DBI backend, which instructs me to build S4 classes that inherit from DBI classes.

From the instructions, to make the DBI classes available, it seems that I only have to list DBI as an import in the DESCRIPTION file.

However, even after doing so, I still get the error

 Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses,  : 
  no definition was found for superclass “DBIDriver” in the specification of class “KazamDriver” 

If I explicit attach DBI with library then this problem go away, but of course one shouldn't use library in package code.

My code:

# DBI-backend.R 
setClass("KazamDriver", contains = "DBIDriver")

# DESCRIPTION
Imports:
  DBI (>= 0.3.0),
  methods

Upvotes: 0

Views: 618

Answers (1)

Heisenberg
Heisenberg

Reputation: 8806

The Imports field in the DESCRIPTION file does not actually import anything. It only makes sure that the listed packages are installed when a user installs your package.

Instead, use NAMESPACE to make other packages or functions available to be used in your package. Also, don't edit NAMESPACE by hand, but use Roxygen2 (details here).

For this particular case, it means

#' @import DBI
setClass("KazamDriver", contains = "DBIDriver")

Upvotes: 1

Related Questions