-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpkgnet-gallery.Rmd
159 lines (146 loc) · 5.15 KB
/
pkgnet-gallery.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
title: "Gallery"
output:
rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Gallery}
%\VignetteEngine{}
%\VignetteEncoding{UTF-8}
---
Welcome to the **pkgnet** gallery! Click any item below to see an example report. Go to the [gallery github page](https://github.com/uptake/pkgnet-gallery) to contribute.
```{r exhibit_data, include = FALSE}
exhibitsList <- list(
list(
package_name = "pkgnet"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pkgnet/pkgnet.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pkgnet/pkgnet.png"
)
, list(
package_name = "pkgnet (Vignette)"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pkgnet-vignette/pkgnet-vignette.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pkgnet/pkgnet.png"
)
, list(
package_name = "bingo"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/bingo/bingo.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/bingo/bingo.png"
)
, list(
package_name = "data.table"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/data_table/data_table.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/data_table/data_table.png"
)
, list(
package_name = "ggplot2"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/ggplot2/ggplot2.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/ggplot2/ggplot2.png"
)
, list(
package_name = "lubridate"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/lubridate/lubridate.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/lubridate/lubridate.png"
)
, list(
package_name = "pipecleaner"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pipecleaner/pipecleaner.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/pipecleaner/pipecleaner.png"
)
, list(
package_name = "updraft"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/updraft/updraft.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/updraft/updraft.png"
)
, list(
package_name = "uptasticsearch"
, report_url = "https://uptake.github.io/pkgnet-gallery/exhibits/uptasticsearch/uptasticsearch.html"
, image_url = "https://uptake.github.io/pkgnet-gallery/exhibits/uptasticsearch/uptasticsearch.png"
)
### ADD NEW EXHIBITS ABOVE THIS LINE ###
)
assertthat::assert_that(
all(vapply(
X = exhibitsList
, FUN = is.list
, FUN.VALUE = logical(1)
))
, msg = "Not all elements of exhibitsList is a list."
)
assertthat::assert_that(
all(vapply(
X = exhibitsList
, FUN = function(exh) {
setequal(names(exh), c("package_name", "report_url", "image_url"))
}
, FUN.VALUE = logical(1)
))
, msg = "Not all elements of exhibitsList have 'package_name', 'report_url', 'image_url'"
)
assertthat::assert_that(
all(vapply(
X = exhibitsList
, FUN = function(exh) {
all(vapply(
X = exh
, FUN = is.character
, FUN.VALUE = logical(1)
))
}
, FUN.VALUE = logical(1)
))
, msg = "Some exhibit(s) have non-character values for 'package_name', 'report_url', or 'image_url'"
)
# Sort exhibits alphabetically by name
exhibitsList <- exhibitsList[order(
# Pull out package_name to use with order to reorder
vapply(exhibitsList, `[[`, i = "package_name", FUN.VALUE = character(1))
)]
```
```{r write_html, include = FALSE}
# Template for one cell in exhibit table, for use with glue
cellTemplate <- '
<td width="33%" style="text-align:center">{package_name}<br>
<a href="{report_url}">
<img width="300" src="{image_url}">
</a>
</td>
'
numRows <- ceiling(length(exhibitsList)/3)
cellToRowMapping <- ceiling(1:length(exhibitsList)/3)
# Generate vector of row html blobs
rowHTML <- vapply(
X = 1:numRows
, FUN = function(row) {
paste('<tr>'
# Paste together cells
, paste(
# Generate cell HTML
vapply(
X = exhibitsList[cellToRowMapping == row]
, FUN = function(exh) {
glue::glue(
cellTemplate
, package_name = exh[['package_name']]
, report_url = exh[['report_url']]
, image_url = exh[['image_url']]
)
}
, FUN.VALUE = character(1)
)
, collapse = "\n"
)
, '</tr>'
, sep = '\n'
)
}
, FUN.VALUE = character(1)
)
tableHTML <- paste(
'<table>'
, paste(rowHTML, collapse = '\n')
, '</table>'
, sep = "\n"
)
```
```{r html_output, echo = FALSE}
knitr::asis_output(htmltools::htmlPreserve(tableHTML))
```