Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Roxygen to make S3method in NAMESPACE

Tags:

r

roxygen2

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?

like image 545
pdb Avatar asked Mar 31 '15 03:03

pdb


1 Answers

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.

like image 183
pdb Avatar answered Oct 10 '22 19:10

pdb