pkgdown::build_reference() fails on exported 'matches' function
gladkia opened this issue · comments
Hi,
Overview
It seems that pkgdown::build_reference()
fails if the exported function is named 'matches'.
Such function can be e.g. found in testthat
package:
testthat::matches
function(regexp, all = TRUE, ...) {
warning(
"matches()
is deprecated. Please useexpect_match()
instead.",
call. = FALSE
)
function(x) expect_match(x, regexp, all = all, ...)
}
<environment: namespace:testthat>
How to reproduce
Add matches
to references in _pkgdown.yml:
gladkia@gladkia-UHMD6M testthat % git diff
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 209eea3d..62abeb34 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -53,6 +53,7 @@ reference:
- skip
- teardown_env
- set_state_inspector
+ - matches
- title: Run tests
contents:
Then run:
> pkgdown::init_site()
> pkgdown::build_reference()
Observed error:
-- Building function reference -------------------------------------------------------------------------------------------------------------------------------------
Error in `map2()`:
ℹ In index: 6.
Caused by error in `purrr::map()`:
ℹ In index: 5.
Caused by error:
! In '_pkgdown.yml', topic must be a known topic name or alias
✖ Not 'matches'
Run `rlang::last_trace()` to see where the error occurred.
Context
Please see more detailed context here.
I see the same error. It looks like the problem is with the YAML parser, because a workaround is to include that topic using
- contents:
- matches("^matches$")
and the same problem happens if you have a function named starts_with
, or the other pattern names: ends_with
, has_keyword
, has_concept
, lacks_concepts
.
The problem appears to be happening here:
https://github.com/r-lib/pkgdown/blame/3979e7c0afbba4503248dc8a6d04fe0a2e03f26f/R/topics.R#L136-L142
The code has already put the aliases as entries in env
, but it also put the selector functions matches(), starts_with()
etc. into the same environment. I think the solution is to use two separate environments for these. I'll see if I can put together a PR.