R: Expand an S3 method defined in another package

房东的猫 提交于 2020-05-13 13:35:46

问题


Let's say that package A defines and documents foo() and implements it for bar1 objects.

In a new package B, I would like to expand this method and add its support for bar2 objects.

Currently, I start by reexporting the method:

#' @rdname foo
#' @importFrom A foo
#' @export
A::foo

And then went on extending its behaviour:

#' @rdname foo
#' @method foo bar2
#' @export
foo.bar2 <- function(x, newparam = 3.14, ...){
  dosomething(x, newparam)
}

Unfortunately, it seems like this creates a conflict upon devtools checking, which returns the following warning:

> checking Rd metadata ... WARNING
  Rd files with duplicated name 'reexports':
    'foo.Rd'
  Rd files with duplicated alias 'reexports':
    'foo.Rd'

Thus, I wonder what this the best way of expanding a method without creating conflict in definition or documentation? Can I do this without having to Depend on the package A? Thanks!

来源:https://stackoverflow.com/questions/55465721/r-expand-an-s3-method-defined-in-another-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!