从另一个包扩展 S4 class:reconcilePropertiesAndPrototype 错误

Extending a S4 class from another package: reconcilePropertiesAndPrototype error

我正在尝试为 RJDBC::JDBCConnection 编写一个子 class,因为我需要自定义方法来使用 dplyr#2941 (originally from here 中的方法连接 dbplyr 包。但是,我不是要覆盖 *.JDBCConnection 方法,而是想为 JDBCConnection 的子 class 编写方法。

因此,根据 this Stack Overflow question 的建议,我写了我的包,基本上是这样的:

### 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 <yourself@somewhere.net>
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

我要扩展的class存在,可以用help("JDBCConnection-class", package = "RJDBC")检查。

在此包中调用 devtools::document() returns 出现以下错误:

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"

我也试过用@importClassesFromas per this SO question替换@import,结果还是一样。

如何让 document() 变为 运行?

您还需要添加

Imports: RJDBC

到您的 DESCRIPTION 文件。例如,参见 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.

在那之后,你的包裹 document() 对我来说没问题。

当我不依赖 roxygen2 编写我的 DESCRIPTION 文件而是自己添加包时,我成功地记录了包。 NAMESPACEroxygen2 管理。

如果我添加行

Imports: methods, RJDBC

Depends: RJDBC

手动添加到DESCRIPTION文件,devtools::document()运行无误。

[duckmayr 同时发现]