Skip to content
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

pkgdown::build_reference() fails on exported 'matches' function #2396

Closed
gladkia opened this issue Feb 14, 2024 · 2 comments · Fixed by #2397
Closed

pkgdown::build_reference() fails on exported 'matches' function #2396

gladkia opened this issue Feb 14, 2024 · 2 comments · Fixed by #2397

Comments

@gladkia
Copy link

gladkia commented Feb 14, 2024

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 use expect_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.

@dmurdoch
Copy link
Contributor

dmurdoch commented Feb 14, 2024

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.

@dmurdoch
Copy link
Contributor

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.

dmurdoch added a commit to dmurdoch/pkgdown that referenced this issue Feb 14, 2024
SebKrantz pushed a commit to SebKrantz/pkgdown that referenced this issue Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants