-
Notifications
You must be signed in to change notification settings - Fork 756
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
load_all() glitch with unexported S3 methods #2293
Comments
My full session info:
|
This is just how R works with registered methods after R 4.0. You need to explicitly register the S3 methods with |
Thanks for the info @jimhester. It might be good to mention this in the docs for
which is technically true, but as you can see, a bit misleading in the case of S3 methods. |
This is tripping me up, too. I just want to confirm about some behavior since I'm having issues finding documentation on this change. I get the following behavior: # generics.R
input <- function(x) {
UseMethod("input")
}
input.character <- function(x){
print(x)
}
my_input <- function(x){
input(x)
}
# Calling input("test") FAILS
# calling my_input("test") WORKS!!!! WTF!?! devtools::load_all()
input("test")
#> Error in input("test"): could not find function "input"
my_input("test")
#> Error in my_input("test"): could not find function "my_input" Calling the generic directly fails, but calling a function wrapping the generic succeeds. I guess I'm struggling to reason about when Anyway, is there some reading material on this? My googling is landing me on pre-R 4.0 references. I understand why |
It is mentioned in the R news for R 4.0
This would only work previously because unregistered methods defined in the package were on the search path in between the global environment and the base environment. But R 4.0+ does not look there anymore for S3 methods. |
Ah, got it. I misinterpreted that news line. Thanks! |
Just to clarify, internal S3 methods do not need to be exported. They only need an |
The standard tag to use is |
But doesn't that export the presumably internal method? |
It only registers it. With roxygen you can't actually "export" an S3 method unless you use a raw namespace directive. The distinction between exporting and registering is important for technical users but not so much for regular users. So |
yeah to be explicit |
I think the confusion could be cleared up by adding a warning in roxygen when S3 methods are not registered with |
…nd properly. We were getting hosed during unit testing because R v4.0.x chnaged the way S3 generics are found, and we now have to add an `@export` roxygen tag to internal S3 functions for things to work like before. Here is a more thorough / accurate discussion of the topic and suggested fix which was implemented in this commit: r-lib/devtools#2293
- Use export on S3methods (required in R > 4, see r-lib/devtools#2293 (comment)) - Use versioned wikipedia urls - Skip if wikipedia cannot be reached
I'm wondering if I've messed up my installation somehow, as this seems to be a fairly fundamental issue.
I'm using R 4.0.2 on Windows, with devtools 2.3.0. When I run
load_all()
on a package under development, R doesn't find S3 methods that aren't exported (ie, aren't present in the NAMESPACE file).Reproducible example:
devtools::create(".")
R/file1.R
containing:devtools::document()
anddevtools::load_all()
The error goes away if I add
@export
directives to thefunc
andfunc.cls
functions, redocument and reload. This behaviour wasn't present under R 3.6.x.The text was updated successfully, but these errors were encountered: