From 548a9493b72ff93d3ed8392d4ad30b77d8b15fa5 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 3 Jan 2024 13:34:43 +1300 Subject: [PATCH] Parse S3 methods with non-syntactic names (#2385) `\method{}`, unlike `\S4method{}`, requires non-syntactic names to be escaped with backticks, so we don't need to escape again. Fixes #2384 --- NEWS.md | 2 ++ R/usage.R | 2 +- tests/testthat/test-usage.R | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cff5f58be..4d6687bc0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/usage.R b/R/usage.R index aa88be084..84f256af4 100644 --- a/R/usage.R +++ b/R/usage.R @@ -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 diff --git a/tests/testthat/test-usage.R b/tests/testthat/test-usage.R index 76757f64b..4a66acc61 100644 --- a/tests/testthat/test-usage.R +++ b/tests/testthat/test-usage.R @@ -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") @@ -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")