Skip to content

Commit

Permalink
Parse S3 methods with non-syntactic names
Browse files Browse the repository at this point in the history
`\method{}`, unlike `\S4method{}`, requires non-syntactic names to be escaped with backticks, so we don't need to escape again.

Fixes #2384
  • Loading branch information
hadley committed Dec 12, 2023
1 parent 13d8d62 commit 0938484
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pkgdown (development version)

* Correct parse usage for S3 methods with non-syntactic class names (#2384).

* Deprecated `build_favicon()` was removed (`build_favicons()` remains).
* Use [cli](https://github.com/r-lib/cli) to provide interactive feedback.
* Preserve Markdown code blocks with class rmd from roxygen2 docs (@salim-b, #2298).
Expand Down
2 changes: 1 addition & 1 deletion R/usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ usage_code.tag_S3method <- function(x) {
generic <- paste0(usage_code(x[[1]]), collapse = "")
class <- paste0(usage_code(x[[2]]), collapse = "")

paste0("S3method(`", generic, "`, `", class, "`)")
paste0("S3method(`", generic, "`, ", class, ")")
}

#' @export
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ test_that("can parse function/methods", {
expect_equal(usage$name, "f")
expect_equal(usage$signature, "bar")

usage <- parse_usage("\\S3method{f}{`foo bar`}(x)")[[1]]
expect_equal(usage$type, "s3")
expect_equal(usage$name, "f")
expect_equal(usage$signature, "foo bar")

usage <- parse_usage("\\S4method{f}{bar,baz}(x)")[[1]]
expect_equal(usage$type, "s4")
expect_equal(usage$name, "f")
Expand All @@ -36,6 +41,11 @@ test_that("can parse function/methods", {
expect_equal(usage$name, "f")
expect_equal(usage$signature, c("function", "function"))

usage <- parse_usage("\\S4method{f}{function,foo bar}(x, y)")[[1]]
expect_equal(usage$type, "s4")
expect_equal(usage$name, "f")
expect_equal(usage$signature, c("function", "foo bar"))

usage <- parse_usage("pkg::func()")[[1]]
expect_equal(usage$type, "fun")
expect_equal(usage$name, "func")
Expand Down

0 comments on commit 0938484

Please sign in to comment.