findR

Find Code Snippets, R Scripts, R Markdown, PDF and Text Files with Pattern Matching


Keywords
find, markdown, package, pdf, r, scripts, txt
License
GPL-3.0

Documentation

CRAN_Status_Badge Licence cranlogs

findR

The findR functions findRscript, findRmd, findPDF, and findtxt scan all directories and subdirectories of a given path for R scripts, R Markdown, PDF and text files with content that matches a specific pattern. Files found can be copied to a folder. reminder prints examples of previously used code directly to the console.

Installation

The version 0.2.0 is on CRAN, and you can install it by:

install.packages("findR")

For regularly updated version (latest: 0.2.1) install from GitHub:

install.packages("devtools")
devtools::install_github("zumbov2/findR")

Example reminder

reminder serves as a memory aid for previously used code. Given a specific path, it searches for code examples of a function. Hits are printed one by one to the console. In the example below, the number of lines displayed after the matching pattern (function) is specified using the argument after.

reminder(func = "chordDiagram", 
         path = "myDataViz", 
         after = 7)

Example findRscript

Hmm, I've used the circlize package before, but I can't remember where or when! I apply findRscript to the main directory of my R projects.

findRscript(pattern = "circlize", 
            path = "C:/Users/David Zumbach/Desktop/R", 
            show.results = F,
            copy = T,
            folder = "myChordScripts")

12 seconds later:

Number of R scripts scanned: 1155
Number of R scripts with matching content: 20
Total number of matches: 40

Example findPDF

Too many papers to read?

findPDF helps you focus!

findPDF(pattern = "tensorflow",
        path = "2017/machine_learning", 
        copy = T, 
        folder = "2017/tensorflow")

15 seconds later and you've got your new reading list:

Some gimmickry

What ggplot2 type am I? Let's find out with findR.

geom_types <- c("geom_bar", "geom_line", "geom_point", "geom_histogram")
hits <- vector(mode = "numeric", length = 4)

for (i in 1:length(geom_types)) {
  
  hits[i] <- nrow(findRscript(pattern = geom_types[i], comments = F))
  
}

The tension is getting higher.

library(tidyverse)
ggstats <- data_frame(type = geom_types, freq = hits)

ggstats %>%
  mutate(type = factor(type, levels = type[order(freq, decreasing = T)])) %>%
  ggplot(aes(type, freq)) +
  geom_bar(stat = "identity") +
  theme_minimal() + 
  labs(x = "", y = "")
  
ggsave("type.png", dpi = 500)

Tadaaa...

Punkt. Aus. Ende.