Highlight text within an R object which matches a given regex. This only works in a terminal which supports ANSI colour codes.

There are slightly different versions of the highlighting function depending upon which text version of the object you'd like to match against:

hl_grep

- the given object x must already be a character string

hl_grep_character

- performs the matching after first calling as.character(x)

hl_grep_print

- performs the matching against the default print(x) output

hl_grep_deparse

- performs the matching after first calling deparse1(x)

hl_grep_str

- performs the matching on the output of calling str(x)

hl_grep(x, pattern, fg = "black", bg = "yellow", ..., perl = TRUE)

hl_grep_character(x, pattern, fg = "black", bg = "yellow", ...)

hl_grep_print(x, pattern, fg = "black", bg = "yellow", ...)

hl_grep_deparse(x, pattern, fg = "black", bg = "yellow", ...)

hl_grep_str(x, pattern, fg = "black", bg = "yellow", ...)

Arguments

x

character string

pattern

regular expression string. Note: don't get too fancy here

fg, bg

any valid R colour specification e.g. 'hotpink', '#335588'

...

extra args passed to gsub

perl

logical. use perl style regex. default: TRUE