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.
It 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.
And the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("s-fleck/sifr")
library(sifr)
tf <- tempfile(fileext = ".csv")
write.csv(cars, tf)
x <- sif("26", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
print(x)
#> Results for 26
#>
#> C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv
#> 9 "8",10,26
#> 17 "16",13,26
#> 21 "20",14,26
#> 26 "25",15,26
#> 27 "26",15,54
as.data.frame(x)
#> path ln
#> 1 C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv 9
#> 2 C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv 17
#> 3 C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv 21
#> 4 C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv 26
#> 5 C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv 27
#> pos contents
#> 1 8, 9 "8",10,26
#> 2 9, 10 "16",13,26
#> 3 9, 10 "20",14,26
#> 4 9, 10 "25",15,26
#> 5 2, 3 "26",15,54
sed_replace("26", "twentysix", dir = dirname(tf), path_pattern = ".*\\.csv$")
#> Warning in system2("sed", sprintf("-i 's/%s/%s/%s' %s", pattern, replace, :
#> '"sed"' not found
#> Warning in system2("sed", sprintf("-i 's/%s/%s/%s' %s", pattern, replace, :
#> '"sed"' not found
#> Warning in system2("sed", sprintf("-i 's/%s/%s/%s' %s", pattern, replace, :
#> '"sed"' not found
#> Warning in system2("sed", sprintf("-i 's/%s/%s/%s' %s", pattern, replace, :
#> '"sed"' not found
#> Warning in system2("sed", sprintf("-i 's/%s/%s/%s' %s", pattern, replace, :
#> '"sed"' not found
#> Results for 26
#>
#> C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv
#> 9 "8",10,26
#> 17 "16",13,26
#> 21 "20",14,26
#> 26 "25",15,26
#> 27 "26",15,54
sif("26", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
#> Results for 26
#>
#> C:/Users/STEFAN~1.FLE/AppData/Local/Temp/RtmpEF7LXd/file60d43e313812.csv
#> 9 "8",10,26
#> 17 "16",13,26
#> 21 "20",14,26
#> 26 "25",15,26
#> 27 "26",15,54
sif("twentysix", dir = dirname(tf), markers = FALSE, path_pattern = ".*\\.csv$")
#> Results for twentysix
#> No matches found
unlink(tf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.