r-lib / pkgdown

Generate static html documentation for an R package
https://pkgdown.r-lib.org/
Other
721 stars 335 forks source link

Resolve https://github.com/r-lib/pkgdown/issues/2727 #2728

Closed lcolladotor closed 4 months ago

lcolladotor commented 4 months ago

This commit implements the change @hadley proposed at https://github.com/r-lib/pkgdown/issues/2727#issuecomment-2233517302 to the internal function needs_tweak(). This does resolve the small reproducible example I described, though I ignore if there are other situations where it wouldn't work for.

hadley commented 4 months ago

Would you mind adding a test too please?

jayhesselberth commented 4 months ago

I think you can just test the usage2text helper, which throws the same error in the current version. FWIW, foo()() is fine.

library(pkgdown)

pkgdown:::usage2text("viridisLite::viridis(21)")
#> Error in is_call(x) && !is_call(x, "=") && !is_syntactic(x[[1]]): 'length = 3' in coercion to 'logical(1)'

pkgdown:::usage2text("foo()()")
#> [1] "foo()()"

Created on 2024-07-22 with reprex v2.1.1 So you could add this test to tests/testthat/test-usage.R:

test_that("usage2text can parse symbols (#2727)", {
    expect_no_error(usage2text("viridisLite::viridis(21)"))
})
lcolladotor commented 4 months ago

Thanks @jayhesselberth!

I added the test you proposed to tests/testthat/test-usage.R. I put it at the end of "Reference index" section of tests, though you might decide that it fits better elsewhere.