Skip to content

Commit

Permalink
to(), rework auto() based on downliot
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Feb 24, 2024
1 parent a5e9dfd commit 4b991be
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 106 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(auto)
export(to)
importFrom(cli,cli_abort)
importFrom(rlang,enexpr)
importFrom(rlang,is_call)
importFrom(rlang,is_string)
15 changes: 5 additions & 10 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ autolink_pkg <- function(x) {
stringr::str_replace_all(
x, rx_pkg,
function(pkg) {
to(package = stringr::str_extract(pkg, rx_pkg, group = 1))
pkg <- stringr::str_extract(pkg, rx_pkg, group = 1)
url <- downlit::href_package(pkg)
glue::glue('<a href="{url}">{{{pkg}}}</a>')
}
)
}

autolink_call <- function(x) {
rx_call <- glue::glue("[{{]({rx_valid_pkg})::({rx_valid_fun})[(][)][}}]")
rx_call <- glue::glue("({rx_valid_pkg})::({rx_valid_fun})\\(\\)")
stringr::str_replace_all(
x, rx_call,
function(call){
to(
package = stringr::str_extract(call, rx_call, group = 1),
topic = stringr::str_extract(call, rx_call, group = 2)
)
}
x, rx_call, downlit::autolink
)

}
Expand All @@ -37,5 +33,4 @@ auto <- function() {

default_text_hook(x)
})

}
47 changes: 0 additions & 47 deletions R/to.R

This file was deleted.

13 changes: 6 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ pak::pak("tadascience/link")

## Example

This is a basic example which shows you how to solve a common problem:
Include this in your `Rmd` or `qmd` document to turn
`<pkg>::<fun>()` and `{<pkg>}` into hyperlinks.

```{r example}
link::to(package = "admiral")
link::to("summarise", package = "dplyr")
link::to(tidyr::gather)
````
```{r, echo = FALSE}
link::auto()
```
````
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,5 @@ pak::pak("tadascience/link")

## Example

This is a basic example which shows you how to solve a common problem:

``` r
link::to(package = "admiral")
#> <a href="https://pharmaverse.github.io/admiral/">admiral</a>

link::to("summarise", package = "dplyr")
#> <a href="https://dplyr.tidyverse.org/reference/summarise.html">dplyr::summarise()</a>

link::to(tidyr::gather)
#> <a href="https://tidyr.tidyverse.org/reference/gather.html">tidyr::gather()</a>
```
Include this in your `Rmd` or `qmd` document to turn `<pkg>::<fun>()`
and `{<pkg>}` into hyperlinks.
25 changes: 0 additions & 25 deletions man/to.Rd

This file was deleted.

0 comments on commit 4b991be

Please sign in to comment.