knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%") knitr::opts_knit$set(root.dir = system.file("extdata/testing", package = "scriptsearch"))
Scriptsearch is an R package intended to help people search through their previous work. Poorly documented code can be hard to look back on, preventing you from reusing the solutions you've already written. This package contains two functions to help you search through your scripts.
Install scriptsearch from GitHub with:
# install.packages("devtools") devtools::install_github("carlos-r-git/scriptsearch")
To view exercises for testing scriptsearch, add build_vignettes = TRUE
to the install function and view the vignette with browseVignettes("scriptsearch")
# install.packages("devtools") devtools::install_github("carlos-r-git/scriptsearch, build_vignettes = TRUE") browseVignettes("scriptsearch")
(Coming soon) You can install the released version of scriptsearch from CRAN with:
install.packages("scriptsearch")
The function scriptsearch()
lists all files in a directory (defaults to present working directory) that contain specified search terms.
library(scriptsearch) scriptsearch("example")
By default scriptsearch()
will add escape characters to special characters in the searchterms string (using this method). The special characters recognised are:
\\ ^ $ . | ? * + ( ) [ {
scriptsearch("t.test")
showlines()
can then be used on the output of scriptsearch
to show all lines containing hits from the n^th^ file in the list.
library(scriptsearch) data <- scriptsearch("example") showlines(data, 2)
table1 <- data.frame("Argument" = c("searchterms", "dir", "rm", "filetypes", "escape"), "Default" = c("N/A", "\".\"", "TRUE", "c(\"R\", \"Rmd\")", "TRUE"), "Function" = c("Strings to search for", "Directory to search", "Remove files with no hits from output", "File endings recognised", "Add escape characters"), "Example" = c("c(\"text1\", \"text2\")", "\"./scripts\"", "TRUE", "txt", "TRUE")) table1 %>% knitr::kable()
table2 <- data.frame("Argument" = c("data", "n", "open"), "Default" = c("N/A", "N/A", "TRUE"), "Function" = c("Table containing files and searchterms", "Index of the file to be searched", "Open selected file"), "Example" = c("data <- scriptsearch(\"./scripts\", \"text\")", "1", "TRUE")) table2 %>% knitr::kable()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.