Skip to content

Commit

Permalink
Merge pull request #7 from tadascience/errors
Browse files Browse the repository at this point in the history
Forgiving `to_pkg()` and `to_call()`
  • Loading branch information
romainfrancois authored Mar 9, 2024
2 parents cf81948 + a525856 commit b1bad2f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,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(tags$span(link_text, class = "r-link-pkg-error"))
}
link <- tags$a(link_text, href = url, class = "r-link-pkg", target = "_blank")

switch(
Expand All @@ -85,12 +88,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(
Expand Down

0 comments on commit b1bad2f

Please sign in to comment.