From f3b47282e3dcb2500abde65bbd0a07c5e6fbbe2e Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Sat, 9 Mar 2024 18:51:43 +0100 Subject: [PATCH 1/2] skip errors for to_pkg() --- R/auto.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/auto.R b/R/auto.R index e9d1869..cf4e510 100644 --- a/R/auto.R +++ b/R/auto.R @@ -66,9 +66,12 @@ get_title <- function(url) { #' @export to_pkg <- function(pkg, type = c("tooltip", "plain"), keep_braces = TRUE, ...) { type <- rlang::arg_match(type) + link_text <- glue::glue(if (keep_braces) "{{{pkg}}}" else "{pkg}") url <- downlit::href_package(pkg) - link_text <- glue::glue(if (keep_braces) "{{{pkg}}}" else "{pkg}") + if (is.na(url)) { + return(link_text) + } link <- tags$a(link_text, href = url, class = "r-link-pkg", target = "_blank") switch( From a52585667daa942884a700b6e39e5ec5024ff546 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Sat, 9 Mar 2024 18:55:42 +0100 Subject: [PATCH 2/2] forgiving to_call() --- R/auto.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/auto.R b/R/auto.R index cf4e510..74d36c2 100644 --- a/R/auto.R +++ b/R/auto.R @@ -70,7 +70,7 @@ to_pkg <- function(pkg, type = c("tooltip", "plain"), keep_braces = TRUE, ...) { url <- downlit::href_package(pkg) if (is.na(url)) { - return(link_text) + return(tags$span(link_text, class = "r-link-pkg-error")) } link <- tags$a(link_text, href = url, class = "r-link-pkg", target = "_blank") @@ -86,12 +86,16 @@ to_pkg <- function(pkg, type = c("tooltip", "plain"), keep_braces = TRUE, ...) { to_call <- function(call, type = c("tooltip", "plain"), keep_pkg_prefix = TRUE, ...) { type <- rlang::arg_match(type) - url <- downlit::autolink_url(call) link_text <- if (keep_pkg_prefix) { call } else { glue::glue("{fun}()", fun = stringr::str_extract(call, rx_call, group = 2)) } + + url <- downlit::autolink_url(call) + if (is.na(url)) { + return(tags$span(link_text, class = "r-link-pkg-error")) + } link <- tags$a(link_text, href = url, class = "r-link-call", target = "_blank") switch(