Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jbgruber/highlightr

R package to highlight words in text :pencil2:
https://github.com/jbgruber/highlightr

Last synced: 3 months ago
JSON representation

R package to highlight words in text :pencil2:

Awesome Lists containing this project

README

        

---
output: github_document
---

# highlightr: highlight text in R output

[![Travis build status](https://travis-ci.org/JBGruber/highlightr.svg?branch=master)](https://travis-ci.org/JBGruber/highlightr)
[![Codecov test coverage](https://codecov.io/gh/JBGruber/highlightr/branch/master/graph/badge.svg)](https://codecov.io/gh/JBGruber/highlightr?branch=master)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

When you hate paper and pens but still want to highlight stuff.

**If you want this project to become better, please don't hesitate to file an [issue report](https://github.com/JBGruber/rwhatsapp/issues) or create pull requests. Thanks.**

## Installation

You can install highlightr from GitHub with:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("JBGruber/highlightr")
```

## Usage

You can use `highlightr` with different output formats:

### HTML/Interactive

If you run your code interactively (for example in `RStudio`), the `highlight` function displays a html document in the Viewer pane (in `RStudio`) or separate window:

```{r eval=FALSE}
library("highlightr")
library("tibble")
text <- c("This is a good test with some bad words", "bad guy vs good guy")
dict <- tibble(
feature = c("good", "bad"),
bg_colour = c("#2ca25f", "#de2d26")
)
highlight(text, dict)
```

![highlightr.gif](./man/figures/highlightr.gif)

If you place this code chunk in an `RMarkdown` document with `output: html_document`, the highlighted text will appear in the knitted **HTML** output.

### LaTeX/PDF

If you want to output a PDF, you need to include two LaTeX packages in your header: `xcolor` and `soul`. You can do so in an `RMarkdown` document with the argument `header-includes` like this:

---

output: pdf_document
header-includes:
- \usepackage{xcolor}
- \usepackage{soul}
---

`r ''````{r results='asis'}
library("highlightr")
library("tibble")
text <- c("This is a good test with some bad words", "bad guy vs good guy")
dict <- tibble(
feature = c("good", "bad"),
bg_colour = c("#2ca25f", "#de2d26")
)
highlight(text, dict, output = "tex")
```


![PDF](./man/figures/pdf.png)