-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
152 lines (119 loc) · 4.2 KB
/
README.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# gluedown <img src="man/figures/logo.png" align="right" width="120" />
<!-- badges: start -->
[![Lifecycle: experimental][life_badge]][life_link]
[![CRAN status][cran_badge]][cran_link]
![Downloads][dl_badge]
[![Codecov test coverage][cov_badge]][cov_link]
[![R build status][ga_badge]][ga_link]
<!-- badges: end -->
The goal of `gluedown` is to ease the transition from R's powerful vectors to
formatted markdown text. The package uses [`glue()`][glue] to wrap character
vectors in markdown syntax. With the [`knitr`][knitr] package, users can print
the formatted vectors directly to the body of a markdown document.
## Installation
Install the release version from [CRAN][cran]:
```{r release, eval=FALSE}
install.packages("gluedown")
```
The development version can be installed from [GitHub][gh]:
```{r develop, eval=FALSE}
# install.packages("remotes")
remotes::install_github("k5cents/gluedown")
```
## Usage
```{r prepare, warning=FALSE, message=FALSE}
library(gluedown)
library(stringr)
library(rvest)
```
Use the `results='asis'` chunk option to print the formatted output to the body
of a document.
````markdown
`r ''````{r results='asis'}
md_order(x = c("Legislative", "Executive", "Judicial"))
```
````
```{r asis, results='asis', echo=FALSE}
md_order(x = c("Legislative", "Executive", "Judicial"))
```
### Lists
Printing vectors as markdown lists was the initial inspiration for the package.
Here, we use five different functions to create five elements of a new vector.
```{r vector}
inlines <- c(
md_bold("Alabama"),
md_code("Alaska"),
md_link("Arizona" = "https://az.gov"),
md_italic("Arkansas"),
md_strike("California")
)
print(inlines)
```
Then we can print that new vector as a list, including the inline formatting.
```{r bullets, results='asis'}
md_bullet(inlines)
```
### Inline
You can also use `gluedown` to format R [inline code results][inline].
```{r inline}
name <- sample(state.name, size = 1)
abb <- state.abb[match(name, state.name)]
# `r md_bold(name)`
# `r md_italic(abb)`
```
In this case, our randomly selected state is `r md_bold(name)`, which has the
abbreviation `r md_italic(abb)`.
### Pipes
All functions are designed to fit within the tidyverse ecosystem and work with
[pipes][pipe].
```{r pipe, results='asis'}
read_html("https://w.wiki/A58") %>%
html_node("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[.*\\]") %>%
md_quote()
```
### Extensions
The package primarily uses [GitHub Flavored Markdown][gfm], with support
for useful extensions like [task lists][task].
```{r extension, results='asis'}
legislation <- c("Houses passes", "Senate concurs", "President signs")
md_task(legislation, check = 1:2)
```
## Contribute
Please note that the `gluedown` project is released with a
[Contributor Code of Conduct][coc]. By contributing to this project, you agree
to abide by its terms.
<!-- links: start -->
[life_badge]: https://img.shields.io/badge/lifecycle-maturing-blue.svg
[life_link]: https://lifecycle.r-lib.org/articles/stages.html#maturing
[cran_badge]: https://www.r-pkg.org/badges/version/gluedown
[cran_link]: https://CRAN.R-project.org/package=gluedown
[ga_badge]: https://github.com/k5cents/gluedown/workflows/R-CMD-check/badge.svg
[ga_link]: https://github.com/k5cents/gluedown/actions
[cov_badge]: https://codecov.io/gh/k5cents/gluedown/graph/badge.svg?token=Ln4HFpOH2P
[cov_link]: https://app.codecov.io/gh/k5cents/gluedown?branch=master
[dl_badge]: https://cranlogs.r-pkg.org/badges/grand-total/gluedown
[coc]: https://k5cents.github.io/gluedown/CODE_OF_CONDUCT.html
[cran]: https://cran.r-project.org/package=gluedown
[gfm]: https://github.github.com/gfm/
[gh]: https://github.com/k5cents/gluedown
[glue]: https://github.com/tidyverse/glue
[inline]: https://rmarkdown.rstudio.com/lesson-4.html
[knitr]: https://github.com/yihui/knitr
[pipe]: https://magrittr.tidyverse.org/reference/pipe.html
[rmd]: https://github.com/rstudio/rmarkdown
[task]: https://help.github.com/en/articles/about-task-lists
<!-- links: end -->