grepr aims to provide a similar functionality as the bash command grep
and display the results as RStudio source markers
You can install the developent version of grepr from GitHub with:
remotes::install_github("GregorDeCillia/grepr")
The function grepr can be used to find matches in files based on a
regular expression.
library(grepr)
grepr("message")[5:9, ]
| file | line | content |
| :--------------------- | :-------------- | :------------------------------------------------------------------------------------------ |
| R/grepr.R | 60 | message = readLines(file)[line], |
| R/print.R | 5 | rstudioapi::sourceMarkers(name = “grepr”, markup_messages(x), |
| R/print.R | 9 | message(“no matches to show”) |
| R/print.R | 12 | markup_messages \<- function(matches, env_open = “\”, |
| R/print.R | 20 | message \<- match$message |
If grepr is called in RStudio, the results are displayed as RStudio
source
markers.
| Argument | Description |
| -------------------- | ---------------------------------------------------------------------------------- |
| pattern | a character string containing a regular expression |
| dir | a directory from which the search is conducted. Defaults to the working directory. |
| ignore_dotfiles | should hidden files be ignored? Defaults to TRUE |
| file_pattern | a regular expression which can be used to exclude certain files from the search |
grep_umlauts is a wrapper around grepr which looks for umlauts via
the pattern argument. It can be used with a flag ignore_roxygen to
skip Rd Files and roxygen comments.
Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
grep_umlauts(file_pattern = "README\\.Rmd")
| file | line | content |
| :---------------------- | :-------------- | :------------------------------------------------------ |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
| README.Rmd | 61 | Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß |
The function print_substitution_table() can be used to suggest
alternatives
print_substitution_table()
#> the following substitutions should be used if R CMD check adds NOTEs because of umlauts
#> Ä: \u00c4 ä: \u00e4 Ö: \u00d6 ö: \u00f6 Ü: \u00dc ü: \u00fc ß: \u00df
Calls to grepr::grepr() create objects of the class grepr. Those
objects can be used in the following ways.
rstudioapi::sourceMarkers()knitr::kable()as.data.frame() converts the matches into a tidy
data.frame that contains filenames, row numbers, colum numbers and
lengths of the matches.grep_umlauts(file_pattern = "README\\.Rmd") %>% as.data.frame()
#> file line column length message
#> 1 README.Rmd 61 20 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 2 README.Rmd 61 23 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 3 README.Rmd 61 26 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 4 README.Rmd 61 29 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 5 README.Rmd 61 32 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 6 README.Rmd 61 35 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
#> 7 README.Rmd 61 38 1 Supported symbols: Ö, Ä, Ü, ö, ä, ü, ß
[
and ]) get escaped in a way that can affect the markup of
knit_print.grepr():
https://github.com/rstudio/rmarkdown/issues/667") are displayed as fancy quotes (“)
in column contentgrep_package() which respects the contents of .gitignore and
.Rbuildignore by defaultgsub_umlauts() which applies the suggestions in
print_substitution_table() automaticallyAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.