-
Notifications
You must be signed in to change notification settings - Fork 341
/
starwars.Rmd
37 lines (32 loc) · 965 Bytes
/
starwars.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
---
title: "Star Wars films (static HTML)"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Star Wars films (static HTML)}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
This vignette contains some data about the Star Wars films for use in rvest examples and vignettes.
```{r, echo = FALSE, results = "asis"}
library(rvest)
crawl_html <- function(x) {
x %>%
gsub("\r", "", .) %>%
gsub("\n\n", "</p><p>", .) %>%
gsub("\n", " ", .) %>%
paste0("<p>", ., "</p>")
}
film_desc <- function(x) {
glue::glue_data(x, "
<section>
<h2 data-id='{episode_id}'>{title}</h2>
<p>Released: {release_date}</p>
<p>Director: <span class='director'>{director}</span></p>
<div class='crawl'>{crawl_html(opening_crawl)}</div>
</section>")
}
films <- repurrrsive::sw_films
films <- films[order(sapply(films, "[[", "episode_id"))]
descs <- vapply(films, film_desc, character(1))
writeLines(descs)
```