Learn R Programming

gluedown

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.

Installation

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")

Usage

library(gluedown)
library(stringr)
library(rvest)

Use the results='asis' chunk option to print the formatted output to the body of a document.

```{r results='asis'}
md_order(x = c("Legislative", "Executive", "Judicial"))
```
  1. Legislative
  2. Executive
  3. 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.

inlines <- c(
  md_bold("Alabama"),
  md_code("Alaska"),
  md_link("Arizona" = "https://az.gov"),
  md_italic("Arkansas"),
  md_strike("California")
)
print(inlines)
#> [1] "**Alabama**"               "`Alaska`"                 
#> [3] "[Arizona](https://az.gov)" "_Arkansas_"               
#> [5] "~~California~~"

Then we can print that new vector as a list, including the inline formatting.

md_bullet(inlines)
  • Alabama
  • Alaska
  • Arizona
  • Arkansas
  • California

Inline

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 Texas, which has the abbreviation TX.

Pipes

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()

We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.

Extensions

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)
  • Houses passes
  • Senate concurs
  • President signs

Contribute

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.

Copy Link

Version

Install

install.packages('gluedown')

Monthly Downloads

350

Version

1.0.9

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Kiernan Nicholls

Last Published

March 11th, 2024

Functions in gluedown (1.0.9)

md_escape

Backslash escape all punctuation
md_fence

Markdown fenced code block
md_indent

Markdown indented code block
md_label

Markdown link label
md_image

Markdown image links
md_link

Markdown inline link (6.6)
md_italic

Markdown italic emphasis
md_issue

Markdown GitHub issue
md_hardline

Markdown hard line breaks
md_heading

Markdown ATX headings
md_strike

Markdown strikethrough (extension)
md_order

Markdown ordered list
md_list

Markdown generic list
md_reference

Markdown link reference
md_setext

Markdown Setext headings (4.3)
md_softline

Markdown soft line breaks
md_table

Markdown tables (4.10 extension)
md_paragraph

Markdown paragraphs breaks
%>%

Pipe operator
md_quote

Markdown block quotes
md_rule

Markdown horizontal rule (4.1)
md_task

Markdown task list (extension)
md_text

Markdown textual content
md_code

Markdown code span
md_autolink

Markdown autolink
has_knitr

Check if the user has the 'knitr' package installed
gluedown-package

gluedown: A package to format character vectors with markdown.
md_convert

Convert markdown to HTML
md_blank

Markdown blank line
md_bold

Markdown bold emphasis
md_bullet

Markdown bullet list
md_chunk

Markdown code block
md_disallow

Disallow certain raw HTML