项目作者: kiernann

项目描述 :
Wrap R vectors in markdown syntax
高级语言: R
项目地址: git://github.com/kiernann/gluedown.git
创建时间: 2019-10-09T15:21:25Z
项目社区:https://github.com/kiernann/gluedown

开源协议:GNU General Public License v3.0

下载


" class="reference-link">gluedown

Lifecycle:
experimental
CRAN
status
Downloads
Codecov test
coverage
R build
status

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:

  1. install.packages("gluedown")

The development version can be installed from
GitHub:

  1. # install.packages("remotes")
  2. remotes::install_github("k5cents/gluedown")

Usage

  1. library(gluedown)
  2. library(stringr)
  3. library(rvest)

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

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

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

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

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

Inline

You can also use gluedown to format R inline code
results
.

  1. name <- sample(state.name, size = 1)
  2. abb <- state.abb[match(name, state.name)]
  3. # `r md_bold(name)`
  4. # `r md_italic(abb)`

In this case, our randomly selected state is New Hampshire, which
has the abbreviation NH.

Pipes

All functions are designed to fit within the tidyverse ecosystem and
work with pipes.

  1. read_html("https://w.wiki/A58") %>%
  2. html_node("blockquote") %>%
  3. html_text(trim = TRUE) %>%
  4. str_remove("\\[.*\\]") %>%
  5. 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
.

  1. legislation <- c("Houses passes", "Senate concurs", "President signs")
  2. 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.