SkillAgentSearch skills...

Cgrep

Highlighted grep of R objects

Install / Use

/learn @coolbutuseless/Cgrep
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- README.md is generated from README.Rmd. Please edit that file -->

cgrep

<!-- badges: start -->

<!-- badges: end -->

cgrep is a package for highlighting character representations of R objects using regular expressions.

What’s in the box:

  • cgrep() for working directly on character strings
  • cgrep_character() matches against the as.character() output of the object
  • cgrep_deparse() matches against the deparse1() output
  • cgrep_print() matches against the default print() output of the object
  • cgrep_str() matches against the str() representation

Installation

You can install from GitHub with:

# install.package('remotes')
remotes::install_github('coolbutuseless/cgrep')

Example: Highlight a string in a data.frame

library(cgrep)

mtcars |> 
  head(20) |>
  cgrep_print("Merc")
<img src="man/figures/df1.png" />

Highlight a row in a data.frame which matches a word

mtcars |> 
  head(20) |>
  cgrep_print("^.*wood.*?$", fg = 'blue', bg = 'hotpink')
<img src="man/figures/df2.png" />

Highlight text in a string

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>"

cgrep(string, "html", ignore.case = TRUE)
<img src="man/figures/char1.png" />

Highlighting within a character vector

vals <- c('hello', 'there', '#rstats', 'on', 'mastodon')

cgrep(vals, "rstats")
<img src="man/figures/vec_print.png" />
cgrep_deparse(vals, "rstats")
<img src="man/figures/vec_deparse.png" />

Related Software

Acknowledgements

  • R Core for developing and maintaining the language.
  • CRAN maintainers, for patiently shepherding packages onto CRAN and maintaining the repository

Related Skills

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated1y ago
Forks0

Languages

R

Security Score

75/100

Audited on Mar 22, 2025

No findings