Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 methods for S4 classes not properly documented #741

Closed
JoFAM opened this issue May 24, 2018 · 4 comments
Closed

S3 methods for S4 classes not properly documented #741

JoFAM opened this issue May 24, 2018 · 4 comments

Comments

@JoFAM
Copy link

JoFAM commented May 24, 2018

Per the methods manual , the following construct should be used when creating S3 methods for S4 classes. This is eg needed when having a model framework in S4, but one needs to provide predict(), fitted(), coef() , ... methods.

setClass("uncased", contains = "character")
unique.uncased <- function(x, incomparables = FALSE, ...) nextMethod(tolower(x))
setMethod("unique", "uncased", unique.uncased)

And the namespace should contain

S3method(unique, uncased)
exportMethods(unique)

When I try the following :

#' @rdname unique
#' @export
unique.uncased <- function(x, incomparables = FALSE, ...) nextMethod(tolower(x))
#' @rdname unique
#' @export
setMethod("unique", "uncased", unique.uncased)

Then :

  • in the namespace export(unique.uncased) is added.
  • R CMD check gives a note about a possible S3 method being refered to in the manual with its full name.

S3 methods shown with full name in documentation object 'unique':
'unique.uncased'
The \usage entries for S3 methods should use the \method markup and not their full name.

If I use the (deprecated) tag @S3method instead, I have the correct entry in the namespace but still the same note in R CMD check.

@hadley
Copy link
Member

hadley commented Jun 28, 2018

This is a case where you should use @method.

@hadley hadley closed this as completed Jun 28, 2018
@JoFAM
Copy link
Author

JoFAM commented Jul 5, 2018

Checked it, and @method doesn't do anything for the NAMESPACE. I need

S3method(unique, uncased)

in the NAMESPACE file instead of export(unique.uncased) as I get now. @method only adds the correct entry in the Rd file, not in the NAMESPACE file.

@hadley
Copy link
Member

hadley commented Jul 5, 2018

@method tells roxygen that it's a method, @export will then export it correctly.

@JoFAM
Copy link
Author

JoFAM commented Jul 5, 2018

Ah, so I need both tags together. Tried it, seems to work. Thx.

jranke added a commit to jranke/saemixextension that referenced this issue Oct 27, 2021
This fixes the R CMD check error in the example code. Fix found using
a well-known search engine, looking for S3 methods for S4 classes,
leading to r-lib/roxygen2#741. Further search
lead to hints on how to use the @method tag at
https://r-pkgs.org/man.html#man-s3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants