-
Notifications
You must be signed in to change notification settings - Fork 237
Consider checking @export or @exportS3method tags only for exported objects #1592
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
Comments
According to the docs :
but the warning should be more clear. it should also be stated in the hadley/r-pkgs#1032 https://r-pkgs.org/dependencies-in-practice.html#imports-and-exports-related-to-s3 |
There is no item on Write an R extension states that a S3 method must be exported. Also CRAN policy https://cran.r-project.org/web/packages/policies.html does not require such behavior In https://r-pkgs.org/dependencies-in-practice.html#imports-and-exports-related-to-s3
But I don't want others to be able to use it. |
But it seems like adding |
I think registering S3 methods allows functions like If the S3 generic is never exported and not intended for regular users, then there is no need to register to I think what's dangerous is a function registering to |
From https://roxygen2.r-lib.org/articles/namespace.html#s3 (emphasis mine):
|
Hi @gadenbuie Thanks for the article. I have some questions for the S3 generics. I know the answer might exist somewhere, but I figured maybe it's better to ask here since you are the expert. I wonder if the roxygen2 warnings will affect whether a package is accepted/archived on CRAN? To my knowledge, CRAN does not require S3 methods to be registered if they are intended to be internal. If not, then is there any way to suppress the roxygen2 warnings at all?
When I don't export S3 methods nor the generics, I can still call the generic function (within the package functions in the same package) with proper class, and R does not have any trouble finding the method functions. In fact, if I run your example code in globalenv, R can still resolve the S3 without issues. I wonder what's the risk of not explicitly registering the S3 methods? I know in some cases, roxygen2 will interpret the S3 methods as package functions, hence the S3 cannot be registered with the generic correctly. However, that's when the functions are exported and intended for package users. Thanks in advance for solving me puzzles : ) |
From R 3.5.0 onwards, you should register S3 methods even if they are internal. There's some information in Kurt Hornik's S3 Method Lookup blogpost. You can also find lots of discussion about the confusion surrounding the
|
Thanks, I see:
This makes sense. If there are two implementations of S3 methods are available for the same class, then the priority could be a problem, and hence registering the method is required. One thing that was mentioned though was that R will search the topenv of the calling evironment. If the S3 method and generics are in the same package and is only called inside of the package, that means there shouldn't be any problem for R to find the S3 method (defined within the same package) correctly. |
Closing this issue as my questions are well addressed. |
Roxygen throws warings. Export of s3 methods required. See discussion here: r-lib/roxygen2#1592
Roxygen throws warnings. Export of s3 methods required. See discussion here: r-lib/roxygen2#1592
Uh oh!
There was an error while loading. Please reload this page.
I got errors "S3 method
import_lfp.native_brainvis
needs export or exportS3method tag." for internal S3 methodimport_lfp
that is never exported.Wonder how to solve this issue.
The text was updated successfully, but these errors were encountered: