Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/s-fleck/sifr

Sarch and replace in files
https://github.com/s-fleck/sifr

Last synced: 10 days ago
JSON representation

Sarch and replace in files

Awesome Lists containing this project

README

        

---
output: github_document
editor_options:
chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "140%"
)
```
# sifr: search in files

[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)

sifr is a tool for searching text strings and regular expression patterns
recursively in directory trees from within R. It is mainly a convenience
utility for **interactive use**.

sifr supports colored console
output, RStudio source markers, and can also return the search results as
a `data.frame` for further processing. In addition, sifr provides
`sed_replace()` on supported platforms (such as Linux, BSD, macOS) for replacing
regex patterns across directory trees via [sed](https://en.wikipedia.org/wiki/Sed).

## Installation

And the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("s-fleck/sifr")
```
## Example

```{r example}
library(sifr)

tf <- tempfile(fileext = ".csv")
write.csv(cars, tf)

x <- sif("26", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
print(x)
as.data.frame(x)

sed_replace("26", "twentysix", dir = dirname(tf), path_pattern = ".*\\.csv$")
sif("26", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
sif("twentysix", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
unlink(tf)
```