Wrap R vectors in markdown syntax
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
The goal of gluedown
is to ease the transition from R’s powerful vectors to
formatted markdown text. The package uses glue()
to wrap character
vectors in markdown syntax. With the knitr
package, users can print
the formatted vectors directly to the body of a markdown document.
Install the release version from CRAN:
install.packages("gluedown")
The development version can be installed from GitHub:
# install.packages("remotes")
remotes::install_github("k5cents/gluedown")
library(gluedown)
library(stringr)
library(rvest)
Use the results='asis'
chunk option to print the formatted output to the body
of a document.
`r ''````{r results='asis'}
md_order(x = c("Legislative", "Executive", "Judicial"))
```
md_order(x = c("Legislative", "Executive", "Judicial"))
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.
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.
md_bullet(inlines)
You can also use gluedown
to format R inline code results.
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)
.
All functions are designed to fit within the tidyverse ecosystem and work with
pipes.
read_html("https://w.wiki/A58") %>%
html_node("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[.*\\]") %>%
md_quote()
The package primarily uses GitHub Flavored Markdown, with support
for useful extensions like task lists.
legislation <- c("Houses passes", "Senate concurs", "President signs")
md_task(legislation, check = 1:2)
Please note that the gluedown
project is released with a
Contributor Code of Conduct. By contributing to this project, you agree
to abide by its terms.