Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
New 'url_template' (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore authored Nov 3, 2024
1 parent c7d1dcc commit 6247ba8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 31 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
12 changes: 11 additions & 1 deletion R/reference_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#' meta-package.
#'
#' @param x A character vector giving concepts or package names to match.
#' @param url_template Character. A template to generate links to documentation
#' based on the column names of the output -- typically `package` and `topic`,
#' e.g. `"https://maurolepore.github.io/{package}/reference/{topic}.html"`
#' (`glue::glue()` syntax).
#' @param url Character vector of length-1 giving a base url, e.g.
#' "https://maurolepore.github.io/".
#' @param strip_s3class `TRUE` removes the class component of S3 methods.
Expand All @@ -23,11 +27,17 @@ NULL

reference_any <- function(doc) {
force(doc)
function(x, url = NULL, packages = NULL, strip_s3class = TRUE) {
function(x, url_template = NULL, url = NULL, packages = NULL, strip_s3class = TRUE) {
warn_unnattached(x, doc)
pick <- pick_doc(packages = packages, doc = doc, x = x)

result <- tidy_reference(may_add_url(pick, url), strip_s3class)

if (!is.null(url_template)) {
result <- mutate(result, topic = paste0("<a href=", glue::glue(url_template), ">", .data$topic, "</a>")
)
}

result
}
}
Expand Down
6 changes: 4 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ utilities
You may link to documentation online.

```{r}
template <- "<a href=https://www.rdocumentation.org/packages/%s/versions/3.6.2/topics/%s>?</a>"
linked <- transform(datasets, topic = sprintf(template, package, topic))
url_template <- "https://www.rdocumentation.org/packages/{package}/versions/3.6.2/topics/{topic}.html"
linked <- reference_package("datasets", url_template = url_template)
linked["topic"]
knitr::kable(head(linked))
```

Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<!-- badges: start -->

[![R-CMD-check](https://github.com/maurolepore/pkgdoc/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/maurolepore/pkgdoc/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/maurolepore/pkgdoc/graph/badge.svg)](https://app.codecov.io/gh/maurolepore/pkgdoc)
<!-- badges: end -->

The goal of pkgdoc is to make it easy to create a data frame of the
Expand Down Expand Up @@ -100,16 +98,32 @@ utilities
You may link to documentation online.

``` r
template <- "<a href=https://www.rdocumentation.org/packages/%s/versions/3.6.2/topics/%s>?</a>"
linked <- transform(datasets, topic = sprintf(template, package, topic))
url_template <- "https://www.rdocumentation.org/packages/{package}/versions/3.6.2/topics/{topic}.html"
linked <- reference_package("datasets", url_template = url_template)
linked["topic"]
#> # A tibble: 87 × 1
#> topic
#> <chr>
#> 1 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 2 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 3 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 4 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 5 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 6 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 7 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 8 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 9 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> 10 <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topi…
#> # ℹ 77 more rows

knitr::kable(head(linked))
```

| topic | alias | title | concept | package |
|:---|:---|:---|:---|:---|
| <a href=https://www.rdocumentation.org/packages/tools/versions/3.6.2/topics/Adobe_glyphs>?</a> | Adobe_glyphs, charset_to_Unicode | Conversion Tables between Character Sets | Datasets available by data() | tools |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/AirPassengers>?</a> | AirPassengers | Monthly Airline Passenger Numbers 1949-1960 | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/BJsales>?</a> | BJsales, BJsales.lead | Sales Data with Leading Indicator | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/BOD>?</a> | BOD | Biochemical Oxygen Demand | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/CO2>?</a> | CO2 | Carbon Dioxide Uptake in Grass Plants | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/ChickWeight>?</a> | ChickWeight | Weight versus age of chicks on different diets | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/AirPassengers.html>AirPassengers</a> | AirPassengers | Monthly Airline Passenger Numbers 1949-1960 | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/BJsales.html>BJsales</a> | BJsales, BJsales.lead | Sales Data with Leading Indicator | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/BOD.html>BOD</a> | BOD | Biochemical Oxygen Demand | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/CO2.html>CO2</a> | CO2 | Carbon Dioxide Uptake in Grass Plants | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/ChickWeight.html>ChickWeight</a> | ChickWeight | Weight versus age of chicks on different diets | Datasets available by data() | datasets |
| <a href=https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/DNase.html>DNase</a> | DNase | Elisa assay of DNase | Datasets available by data() | datasets |
19 changes: 4 additions & 15 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
AirPassengers
BJsales
CMD
Codecov
ForestGEO
ViewFullTable
autoplot
autoplots
autoplotting
dbh
elev’
fgeo
ChickWeight
DNase
github
https
io
isS
maurolepore
pkgdown
quadrat
serach
sp
sp’
subquadrat
tidymodels
tidyverse
vft
13 changes: 12 additions & 1 deletion man/reference_concept.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/reference_package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test-reference_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ test_that("doesn't include the package-level documentation", {
out <- reference_package("pkgdoc")
expect_false(any(grepl("pkgdoc-package", unique(out$alias))))
})

test_that("takes a `url_template`", {
url_template <- "https://maurolepore.github.io/{package}/reference/{topic}.html"
out <- reference_package("pkgdoc", url_template = url_template)
expect_true(grepl("pkgdoc", out$topic[[1]]))
})

test_that("with bad `url_template` errors gracefully", {
bad <- "https://{bad}/{topic}.html"
expect_error(reference_package("pkgdoc", url_template = bad), "not found")
})

0 comments on commit 6247ba8

Please sign in to comment.