【问题标题】:Extending a S4 class from another package: reconcilePropertiesAndPrototype error从另一个包扩展 S4 类:reconcilePropertiesAndPrototype 错误
【发布时间】:2019-03-06 12:08:47
【问题描述】:

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

因此,根据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

我要扩展的类已经存在,可以通过help("JDBCConnection-class", package = "RJDBC")查看。

在此包中调用 devtools::document() 会返回以下错误:

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() 运行?

【问题讨论】:

    标签: r extends s4 roxygen dbplyr


    【解决方案1】:

    你还需要添加

    Imports: RJDBC
    

    到您的DESCRIPTION 文件。例如,请参阅this guide:

    如果您的包正在使用其他包中的功能,您还需要 在您的说明文件中添加一些行。

    ...

    Imports 用于您的包需要的包,但 不需要用 library() 加载。中提到的包 Roxygen2 cmets 中的 @import 或 @importFrom 语句,或者 函数是通过 :: 运算符访问的,应该在这里。

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

    【讨论】:

      【解决方案2】:

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

      如果我添加线

      Imports: methods, RJDBC
      

      或

      Depends: RJDBC
      

      手动到DESCRIPTION 文件,devtools::document() 运行没有错误。

      [duckmayr 在同一时间发现了它]

      【讨论】:

        猜你喜欢
        • 2015-08-23
        • 1970-01-01
        • 2013-07-18
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多