{emphatic}
augments the output of data.frames, matrices and simple vectors in R by adding user-defined ANSI highlighting.
See the online documentation for vignettes and more examples.
There are separate high-level functions for highlighting data.frames, matrices and simple vectors. There is also a low-level highlghting function which can be used on data.frames and matrices.
The hl_
prefix can be read as highlight
.
hl()
for highlighting data.frameshl_mat()
for highlighting matriceshl_vec()
for highlighting simple atomic vectorshl_loc()
for low-level control of highlighting of both data.frames and matriceshl_opt()
to set some local options on the current emphatic
object e.g. full_colour
option sets 24-bit colour mode.hl_opt_global()
sets global options for highlighting. These values will be the default unless overridden with a call to hl_opt()
for the given emphatic
object.hl_str_diff()
for highlighting string differences.hl_grep(x, pattern)
where x
is a character string.hl_grep_character()
where the general object x
is converted to a string using as.character()
.hl_grep_print()
as above, but converstion to character via print()
hl_grep_deparse()
as above, but using deparse1()
to create string representation of object.hl_grep_str()
as above, but using str()
to create string representation of object.data.frame | matrix | vector | |
---|---|---|---|
High Level | hl() |
hl_mat() |
hl_vec() |
Low Level | hl_loc() |
hl_loc() |
NA |
You can install from GitHub with:
# install.package('remotes')
remotes::install_github('coolbutuseless/emphatic', ref = 'main')
eval()
on user-supplied code and extreme caution should be taken before exposing functions in this package to the internet (e.g. via shiny
)Intro
Specifying rows, columns and colours
Test cases on Real data
volcano
datasetAdvanced:
library(emphatic)
emphatic::hl_opt_global(dark_mode = FALSE)
mtcars |>
hl(c('red', 'white'))
Use emphatic to highlight the mtcars
dataset where:
gear
or carb
columnshotpink
mtcars |>
hl(ggplot2::scale_colour_viridis_c(),
cols = mpg, dest_cols = mpg:am, show_legend = TRUE) |>
hl('hotpink', rows = mpg == max(mpg)) |>
hl_opt(text_contrast = 0.25)
Create a correlation matrix of some of the variables in mtcars
.
Colour the values using red for negative correlations and blue for positive correlations. Values in-between are coloured using a gradient between red and blue. This colouring is applied using ggplot2::scale_colour_gradient2()
.
Highlight locations in a numeric vector which match an expression.
x <- 'hell there!'
y <- 'hello there?'
hl_str_diff(x, y)
x <- 'hello there?'
y <- 'hell there!'
hl_str_diff(x, y)
x <- "Paris in the the spring?"
y <- "Not Paris in the spring!"
hl_str_diff(x, y)
grep()
matches in character representations of objects
mtcars |>
head(20) |>
hl_grep_print("Merc")
mtcars |>
head(20) |>
hl_grep_print("(?m)^.*wood.*?$", fg = 'blue', bg = 'hotpink')
string <-
"<xml>
<this is='not'>a real XML doc</this>
<this is='not'>a real HTML doc</this>
<this is='not'>a real XML doc</this>
<this is='not'>a real XML doc</this>
</xml>"
hl_grep(string, "html", ignore.case = TRUE)
hl_grep_character(pi, "589")