Use Roxygen to make S3method in NAMESPACE

断了今生、忘了曾经 提交于 2019-12-07 15:48:43

问题


I want to export an S3method named [.myclass using roxygen2 and I can't see a clean way to do this.

I need NAMESPACE to have

S3method("[",myclass)

in it or the method can't be used after I require the package, but roxygen2 doesn't appear to want to help me with this.

I can force it to with

#' @S3method [ myclass
setMethodS3("[",
        c(x="myclass"),
        function(x,i) {
blah blah balh
})

but roxygen then says that s3method is deprecated and that I should use @export instead, but

#' @export
setMethodS3("[",
          c(x="myclass"),
          function(x,i) {
  blah blah balh
 })

just doesn't do it. (puts an empty export in the NAMESPACE).

I asked the author of the package and he suggested i use @method and @export, but this also doesn't work

#' @method [ myclass
#' @export
setMethodS3("[",
          c(x="myclass"),
          function(x,i) {
  blah blah balh
 })

also ends up with "export()" in the NAMESPACE

What am I missing?


回答1:


Answer:

Hadley was incredibly helpful and now I realize that I shouldn't be using setMethodS3 but instead just

#' @method [ myclass
#' @export
"[.myclass" <- function(x,i) { blah blah blah }

and then everything works great.



来源:https://stackoverflow.com/questions/29360132/use-roxygen-to-make-s3method-in-namespace

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