Skip to content

Commit 64522c7

Browse files
authored
* document_universe() now outputs the new column type. (#18)
* * New column type to differenciates vignette * Test type vignette * Turn article into vignette * Test with dverse * Pick helpfiles * fixme * refactor * refactor * * Do not link articles * test * style * Refactor * Show helpfiles * Make article * Polish * Prune * Spellcheck
1 parent f772a70 commit 64522c7

File tree

6 files changed

+56
-48
lines changed

6 files changed

+56
-48
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Imports:
2525
Suggests:
2626
DT,
2727
knitr,
28-
testthat
28+
testthat,
29+
withr
2930
Config/Needs/website: rmarkdown
3031
Config/testthat/edition: 3
3132
Encoding: UTF-8

R/document_universe.R

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
document_universe_impl <- function(x, url_template = NULL) {
22
warn_unnattached(x)
3-
pick <- pick_doc(x = x)
3+
pick <- pick_doc(x)
44

5-
out <- tidy_reference(may_add_url(pick, url = NULL), strip_s3class = TRUE)
5+
out <- tidy_reference(pick, strip_s3class = TRUE)
66

77
if (!is.null(url_template)) {
8-
out <- mutate(out, topic = paste0("<a href=", glue::glue(url_template), ">", .data$topic, "</a>"))
8+
out <- mutate(
9+
out,
10+
topic = ifelse(
11+
.data$type == "help",
12+
paste0("<a href=", glue::glue(url_template), ">", .data$topic, "</a>"),
13+
.data$topic
14+
)
15+
)
916
}
1017

1118
out
@@ -59,7 +66,7 @@ pick_doc <- function(x) {
5966

6067
tidy_reference <- function(data, strip_s3class) {
6168
out <- collapse_alias(data, strip_s3class)
62-
out <- select(out, c("topic", "alias", "title", "concept", "package"))
69+
out <- select(out, c("topic", "alias", "title", "concept", "type", "package"))
6370
out <- arrange(out, .data$alias)
6471
out
6572
}
@@ -98,20 +105,3 @@ collapse_alias <- function(data, strip_s3class = FALSE) {
98105
may_strip_s3class <- function(x, .f = s3_strip_class) {
99106
paste(unique(.f(x)), collapse = ", ")
100107
}
101-
102-
may_add_url <- function(x, url) {
103-
if (is.null(url)) {
104-
return(unique(x))
105-
}
106-
unique(link_topic(x, url))
107-
}
108-
109-
link_topic <- function(data, url) {
110-
out <- mutate(
111-
data,
112-
topic = glue("<a href={url}{package}/reference/{topic}>?</a>"),
113-
package = glue("<a href={url}{package}>{package}</a>")
114-
)
115-
116-
arrange(out, .data$package)
117-
}

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ url_template <- "https://{package}.tidyverse.org/reference/{topic}.html"
7777
docs <- dverse::document_universe(packages, url_template)
7878

7979
docs
80-
#> # A tibble: 35 × 5
81-
#> topic alias title concept package
82-
#> <chr> <chr> <chr> <chr> <chr>
83-
#> 1 <a href=https://tibble.tidyverse.org/reference/a… add_… Add … additi… tibble
84-
#> 2 <a href=https://tibble.tidyverse.org/reference/a… add_… Add … additi… tibble
85-
#> 3 <a href=https://glue.tidyverse.org/reference/as_… as_g… Coer… <NA> glue
86-
#> 4 <a href=https://tibble.tidyverse.org/reference/a… as_t… Coer… <NA> tibble
87-
#> 5 <a href=https://tibble.tidyverse.org/reference/c… char… Form… vector… tibble
88-
#> 6 <a href=https://tibble.tidyverse.org/reference/d… digi… Comp… <NA> tibble
89-
#> 7 <a href=https://tibble.tidyverse.org/reference/e… enfr… Conv… <NA> tibble
90-
#> 8 <a href=https://tibble.tidyverse.org/reference/e… exte… Exte… <NA> tibble
91-
#> 9 <a href=https://tibble.tidyverse.org/reference/f… form… Colu… <NA> tibble
92-
#> 10 <a href=https://tibble.tidyverse.org/reference/f… form… Prin… <NA> tibble
93-
#> # ℹ 25 more rows
80+
#> # A tibble: 39 × 6
81+
#> topic alias title concept type package
82+
#> <chr> <chr> <chr> <chr> <chr> <chr>
83+
#> 1 <a href=https://tibble.tidyverse.org/refer… add_… Add … additi… help tibble
84+
#> 2 <a href=https://tibble.tidyverse.org/refer… add_… Add … additi… help tibble
85+
#> 3 <a href=https://glue.tidyverse.org/referen… as_g… Coer… <NA> help glue
86+
#> 4 <a href=https://tibble.tidyverse.org/refer… as_t… Coer… <NA> help tibble
87+
#> 5 <a href=https://tibble.tidyverse.org/refer… char… Form… vector… help tibble
88+
#> 6 <a href=https://tibble.tidyverse.org/refer… digi… Comp… <NA> vign… tibble
89+
#> 7 <a href=https://tibble.tidyverse.org/refer… enfr… Conv… <NA> help tibble
90+
#> 8 <a href=https://glue.tidyverse.org/referen… engi… Cust… <NA> vign… glue
91+
#> 9 <a href=https://tibble.tidyverse.org/refer… exte… Exte… <NA> vign… tibble
92+
#> 10 <a href=https://tibble.tidyverse.org/refer… form… Colu… <NA> vign… tibble
93+
#> # ℹ 29 more rows
9494
```
9595

9696
`knitr::kable()` turns the URLs into clickable links.
@@ -99,11 +99,11 @@ docs
9999
knitr::kable(head(docs, 3))
100100
```
101101

102-
| topic | alias | title | concept | package |
103-
|:---|:---|:---|:---|:---|
104-
| <a href=https://tibble.tidyverse.org/reference/add_column.html>add_column</a> | add_column | Add columns to a data frame | addition | tibble |
105-
| <a href=https://tibble.tidyverse.org/reference/add_row.html>add_row</a> | add_row, add_case | Add rows to a data frame | addition | tibble |
106-
| <a href=https://glue.tidyverse.org/reference/as_glue.html>as_glue</a> | as_glue | Coerce object to glue | NA | glue |
102+
| topic | alias | title | concept | type | package |
103+
|:---|:---|:---|:---|:---|:---|
104+
| <a href=https://tibble.tidyverse.org/reference/add_column.html>add_column</a> | add_column | Add columns to a data frame | addition | help | tibble |
105+
| <a href=https://tibble.tidyverse.org/reference/add_row.html>add_row</a> | add_row, add_case | Add rows to a data frame | addition | help | tibble |
106+
| <a href=https://glue.tidyverse.org/reference/as_glue.html>as_glue</a> | as_glue | Coerce object to glue | NA | help | glue |
107107

108108
`DT::datatabe()` also provides a search box. See [Get
109109
started](https://maurolepore.github.io/dverse/articles/dverse.html).

inst/WORDLIST

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Codecov
33
Lifecycle
44
ORCID
55
Tidyverse
6-
funcitons
6+
dplyr
7+
ggplot
78
pkgdown
89
tibble
910
tidymodels
1011
tidyverse
11-
yml

tests/testthat/test-document_universe.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_that("yields the expected tbl", {
1010
out <- document_universe(c("datasets"))
1111

1212
expect_s3_class(out, "tbl")
13-
expect_named(out, c("topic", "alias", "title", "concept", "package"))
13+
expect_named(out, c("topic", "alias", "title", "concept", "type", "package"))
1414
are_type <- unlist(unique(lapply(out, typeof)))
1515
expect_equal(are_type, "character")
1616
})
@@ -31,8 +31,9 @@ test_that("with no url creates no link", {
3131
})
3232

3333
test_that("with a url creates a link", {
34-
out <- document_universe("datasets", url = "https://blah")$topic[[1]]
35-
expect_true(grepl("href", out))
34+
out <- document_universe("datasets", url = "https://blah")
35+
topic <- out[out$type == "help", "topic"]$topic
36+
expect_true(all(grepl("href", topic)))
3637
})
3738

3839
test_that("srips the class of S3 methods", {
@@ -56,3 +57,17 @@ test_that("with bad `url_template` errors gracefully", {
5657
bad <- "https://{bad}/{topic}.html"
5758
expect_error(document_universe("dverse", url_template = bad), "not found")
5859
})
60+
61+
test_that("vignettes lack a link", {
62+
# Not using dverse because on developer mode there are no vignettes
63+
withr::local_package("tibble")
64+
type <- "vignette"
65+
out <- document_universe("tibble", url_template = "some/url")
66+
topic <- out[out$type == type, ]$topic
67+
68+
# Error if there is no vignette
69+
expect_false(rlang::is_empty(topic))
70+
71+
has_link <- any(grepl("href", topic))
72+
expect_false(has_link)
73+
})

vignettes/articles/dverse.Rmd

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ docs
2525
```
2626

2727
Pick rows and columns to organize the documentation however you like (e.g. by
28-
`package` or `concept`).
28+
`package` or `type`).
2929

3030
```{r}
31-
pick <- docs[c("topic", "title", "package")]
31+
rows <- docs$type == "help"
32+
cols <- c("topic", "title", "package")
33+
pick <- docs[rows, cols]
3234
```
3335

3436
You may generate a clickable table with `DT::datatable()`, which offers great

0 commit comments

Comments
 (0)