https://github.com/jbgruber/highlightr
R package to highlight words in text :pencil2:
https://github.com/jbgruber/highlightr
Last synced: 19 days ago
JSON representation
R package to highlight words in text :pencil2:
- Host: GitHub
- URL: https://github.com/jbgruber/highlightr
- Owner: JBGruber
- Created: 2019-02-14T21:20:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-04T09:39:38.000Z (almost 3 years ago)
- Last Synced: 2025-04-12T06:08:54.508Z (3 months ago)
- Language: R
- Homepage:
- Size: 5.65 MB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---# highlightr: highlight text in R output
[](https://travis-ci.org/JBGruber/highlightr)
[](https://codecov.io/gh/JBGruber/highlightr?branch=master)
[](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)
```
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")
```
