r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

build_site() fails when two .Rd mans have the same \aliases #74

Closed netique closed 3 years ago

netique commented 3 years ago

I have a package, where one function has the same name as the package, which is a case quite often, in my view. The package-level .Rd was built with usethis::use_package_doc(). When I call pkgdown::build_site(new_process = FALSE), following error occurs:

Error in vapply(.x, .f, ..., FUN.VALUE = character(1), USE.NAMES = FALSE) : 
  values must be length 1,
 but FUN(X[[2]]) result is length 2
In addition: Warning messages:
1: In if (rdname == "reexports") { :
  the condition has length > 1 and only the first element will be used
2: In if (rdname == cur_rdname) { :
  the condition has length > 1 and only the first element will be used

Traceback:

href_topic_local(topic)
href_topic(fun_name, pkg)
href_expr(expr[[1]])
autolink_url(text)
FUN(X[[i]], ...)
vapply(.x, .f, ..., FUN.VALUE = character(1), USE.NAMES = FALSE)
map_chr(text, fun, ...)
tweak_children(x, xpath_inline, autolink, replace = "contents")
downlit::downlit_html_node(xml)
markdown(src_path)
build_home_index(pkg, quiet = quiet)
build_home(pkg, override = override, preview = FALSE)
build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_run,
pkgdown::build_site(new_process = FALSE)

In the innermost call, there are two elements in rdnames: "package" and "package-package" (from usethis::use_package_doc()). This is the issue. A clash of two aliases in .Rd.

HenrikBengtsson commented 3 years ago

Just ran into this one as well; I've _R_CHECK_LENGTH_1_LOGIC2_=verbose so I get:

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (topic) 
{
    rdname <- find_rdname(NULL, topic)
    if (is.null(rdname)) {
        loc <- find_rdname_attached(topic)
        if (is.null(loc)) {
            return(NA_character_)
        }
        else {
            return(href_topic_remote(topic, loc$package))
        }
    }
    if (rdname == "reexports") {
        return(href_topic_reexported(topic, getOption("downlit.package")))
    }
    cur_rdname <- getOption("downlit.rdname", "")
    if (rdname == cur_rdname) {
        return(NA_character_)
    }
    if (cur_rdname != "") {
        paste0(rdname, ".html")
    }
    else {
        paste0(getOption("downlit.topic_path"), rdname, ".html")
    }
}
<bytecode: 0x5642d97bad70>
<environment: namespace:downlit>
 --- function search by body ---
Function href_topic_local in namespace downlit has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (rdname == "reexports") { : the condition has length > 1
hadley commented 3 years ago

Would've been helpful to know which packages this occured in.