Reputation: 194
I want to use S3 dispatch for an internal function. However, when I create something like
myfun <- function(x) {
UseMethod("myfun")
}
myfun.someclass <- function(x) {
print(x)
}
roxygen
complains: "S3 method myfun.someclass needs @export or @exportS3method tag."
I figured out that when I rename my function to .myfun()
, all is fine.
Is that the rule? You can't have internal S3 methods unless you prepend the function name with a .
? I couldn't find any documentation related to that, so I'm a bit confused: Are internal S3 methods generally discouraged in packages and I just found a hack, or is that a fine thing to do?
Upvotes: 2
Views: 82
Reputation: 194
For S3 methods, @export
doesn't actually export the method, but instead registers it. The right way to handle this is to register the S3 methods by adding the @export
tag, but not then simply not export the generic function.
Roxygen complains when you don't register an S3 method and from R 3.5 onwards all S3 methods should be registered.
Upvotes: 3