Extending a S4 class from another package: reconcilePropertiesAndPrototype error

464 Views Asked by At

I am trying to write a subclass for RJDBC::JDBCConnection as I need custom methods to connect the dbplyr package using the approach from dplyr#2941 (originally from here). However, I am not overwriting the *.JDBCConnection methods but want to write methods for a subclass of JDBCConnection.

Therefore, following the advise from this Stack Overflow question, I wrote my package which is essentially this:

### R/testclass.R ####################
#' Test class
#'
#' This extends JDBCConnection in package RJDBC
#'
#' @import RJDBC
#'
setClass("TestConnection", contains = "JDBCConnection")

### DESCRIPTION ######################
Package: test
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <[email protected]>
Description: More about what it does (maybe more than one line)
    Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true

The class I want to extend exists, as can be checked with help("JDBCConnection-class", package = "RJDBC").

Calling devtools::document() within this packages returns the following error:

Updating test documentation
Loading test

Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses,  : 
no definition was found for superclass "JDBCConnection" in the specification of class "TestConnection"

I also tried replacing @import with @importClassesFrom as per this SO question, but the result was the same.

How can I get document() to run?

2

There are 2 best solutions below

0
On BEST ANSWER

You also need to add

Imports: RJDBC

to your DESCRIPTION file. See, for example, this guide:

If your package is using functions in other packages, you also need to add some lines to your DESCRIPTION file.

...

Imports is used for packages that are needed by your package but that don’t need to be loaded with library(). Packages referred to in @import or @importFrom statements in your Roxygen2 comments, or whose functions are accessed via the :: operator, should be here.

After that, your package document()'d fine for me.

0
On

I succeeded to document the package when I do not rely on roxygen2 to write my DESCRIPTION file but add the packages myself. NAMESPACE is managed by roxygen2.

If I add the Line

Imports: methods, RJDBC

or

Depends: RJDBC

to the DESCRIPTION file manually, devtools::document() runs without error.

[duckmayr found it out in the same time]