Use Roxygen to make S3method in NAMESPACE
Asked Answered
M

1

6

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?

Mason answered 31/3, 2015 at 3:32 Comment(1)
Instead of posting the answer in your question you should post the answer as an answer. There is nothing wrong with posting an answer to your own question.Annettannetta
M
8

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.

Mason answered 15/4, 2015 at 0:35 Comment(1)
This changed in R 4.0.0 to be more strictMason

© 2022 - 2024 — McMap. All rights reserved.