Skip to content

Commit 9e97a3c

Browse files
authored
Support @exportS3Method NULL (#1551)
To suppress the S3 method warning message. Fixes #1550.
1 parent f4dc9b1 commit 9e97a3c

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* The NAMESPACE roclet now reports if you have S3 methods that are missing
1818
an `@export` tag. All S3 methods need to be `@export`ed (which confusingly
1919
really registers the method) even if the generic is not. This avoids rare,
20-
but hard to debug, problems (#1175).
20+
but hard to debug, problems (#1175). You can suppress the warning with
21+
`@exportS3Method NULL` (#1550).
2122

2223
* `@include` now gives an informative warning if you use a path that doesn't
2324
exist (#1497).

R/namespace.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ roxy_tag_parse.roxy_tag_exportS3Method <- function(x) {
199199
roxy_tag_ns.roxy_tag_exportS3Method <- function(x, block, env) {
200200
obj <- block$object
201201

202+
if (identical(x$val, "NULL")) {
203+
return()
204+
}
205+
202206
if (identical(x$val, "")) {
203207
if (!inherits(obj, "s3method")) {
204208
warn_roxy_tag(x, "must be used with an known S3 method")

tests/testthat/test-namespace.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ test_that("warns if S3 method not documented", {
437437
)
438438
})
439439

440+
441+
test_that("can suppress the warning", {
442+
block <- "
443+
#' @exportS3Method NULL
444+
mean.myclass <- function(x) 1
445+
"
446+
expect_silent(out <- roc_proc_text(namespace_roclet(), block))
447+
expect_equal(out, character())
448+
})
449+
450+
440451
test_that("doesn't warn for potential false postives", {
441452
roc <- namespace_roclet()
442453
expect_no_warning({

vignettes/namespace.Rmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ bizarro.character <- function(x, ...) {
7272
}
7373
```
7474

75+
If you are exporting a method in some other way, you can use `@exportS3Method NULL` to suppress the warning.
76+
7577
You have four options for documenting an S3 method:
7678

7779
- Don't document it; it's not required, and not needed for simple generics where the user won't care about the details.

0 commit comments

Comments
 (0)