findInGit: Find pattern in files of a 'git' repository

Description Usage Arguments Value Examples

View source: R/findInGit.R

Description

Find a pattern in the files with a given extension, in all branches of a 'git' repository.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
findInGit(
  ext,
  pattern,
  wholeWord = FALSE,
  ignoreCase = FALSE,
  perl = FALSE,
  excludePattern = NULL,
  excludeFoldersPattern = NULL,
  root = ".",
  output = "viewer"
)

Arguments

ext

file extension, e.g. "R" or "js"

pattern

pattern to search for, a regular expression, e.g. "function" or "^function"

wholeWord

logical, whether to match the whole pattern

ignoreCase

logical, whether to ignore the case

perl

logical, whether pattern is a Perl regular expression

excludePattern

a pattern; exclude from search the files and folders which match this pattern

excludeFoldersPattern

a pattern; exclude from search the folders which match this pattern

root

path to the root directory to search from

output

one of "viewer", "dataframe" or "viewer+dataframe"; see examples

Value

A dataframe if output="dataframe", otherwise a htmlwidget object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
findGit <- Sys.which("git") != ""
if(findGit){

library(findInGit)
library(R.utils) # to use the `copyDirectory` function
folder1 <- system.file("htmlwidgets", package = "findInGit")
folder2 <- system.file("htmlwidgets", "lib", package = "findInGit")
tmpDir <- paste0(tempdir(), "_gitrepo")
dir.create(tmpDir)
# set tmpDir as the working directory
cd <- setwd(tmpDir)
# copy folder1 in tmpDir
copyDirectory(folder1, recursive = FALSE)
# initialize git repo
system("git init")
# add all files to git
system("git add -A")
# commit files
system('git commit -m "mycommit1"')
# create a new branch
system("git checkout -b newbranch")
# copy folder2 in tmpDir, under the new branch
copyDirectory(folder2, recursive = FALSE)
# add all files to git
system("git add -A")
# commit files
system('git commit -m "mycommit2"')

# now we can try `findInGit`
findInGit(ext = "js", pattern = "ansi")

# get results in a dataframe:
findInGit(ext = "js", pattern = "ansi", output = "dataframe")

# one can also get the widget and the dataframe:
fig <- findInGit(ext = "css", pattern = "color", output = "viewer+dataframe")
fig
FIG2dataframe(fig)

# return to initial current directory
setwd(cd)
# delete tmpDir
unlink(tmpDir, recursive = TRUE, force = TRUE)

}

findInGit documentation built on July 28, 2021, 5:10 p.m.