Skip to content

Commit b1bad2f

Browse files
Merge pull request #7 from tadascience/errors
Forgiving `to_pkg()` and `to_call()`
2 parents cf81948 + a525856 commit b1bad2f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

R/auto.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ get_title <- function(url) {
6868
#' @export
6969
to_pkg <- function(pkg, type = c("tooltip", "plain"), keep_braces = TRUE, ...) {
7070
type <- rlang::arg_match(type)
71+
link_text <- glue::glue(if (keep_braces) "{{{pkg}}}" else "{pkg}")
7172

7273
url <- downlit::href_package(pkg)
73-
link_text <- glue::glue(if (keep_braces) "{{{pkg}}}" else "{pkg}")
74+
if (is.na(url)) {
75+
return(tags$span(link_text, class = "r-link-pkg-error"))
76+
}
7477
link <- tags$a(link_text, href = url, class = "r-link-pkg", target = "_blank")
7578

7679
switch(
@@ -85,12 +88,16 @@ to_pkg <- function(pkg, type = c("tooltip", "plain"), keep_braces = TRUE, ...) {
8588
to_call <- function(call, type = c("tooltip", "plain"), keep_pkg_prefix = TRUE, ...) {
8689
type <- rlang::arg_match(type)
8790

88-
url <- downlit::autolink_url(call)
8991
link_text <- if (keep_pkg_prefix) {
9092
call
9193
} else {
9294
glue::glue("{fun}()", fun = stringr::str_extract(call, rx_call, group = 2))
9395
}
96+
97+
url <- downlit::autolink_url(call)
98+
if (is.na(url)) {
99+
return(tags$span(link_text, class = "r-link-pkg-error"))
100+
}
94101
link <- tags$a(link_text, href = url, class = "r-link-call", target = "_blank")
95102

96103
switch(

0 commit comments

Comments
 (0)