ggrep: Convenience functions for grep

Description Usage Arguments Value Note Author(s) Examples

Description

Grepping in a (my) R directory

Usage

1
2
3
4
grepnot(str,x,value=TRUE)
ggrep( opt = "inr", str, exclude = "", dir =  "/Users/hoffmannc/R/",
           pkg = "", split = FALSE, lines = 10, out = FALSE)
countChar( str, dir="/Users/hoffmannc/R/", pkg="",split=FALSE,out=FALSE)

Arguments

str

string to do grep for


exclude

string to exclude from grep


x

array of strings to check with grep.


value

Boolean, third argument to grep ('ignore.case').


opt

options for 'grep' without leading '-'


dir

name of root directory to do grep in


pkg

package name to do grep in; may be "" if dir itself is meant.

split

should str be split in single characters? If so, only unique characters will be searched.

lines

a maximum of 'lines' lines will be returned

out

logical, should intermediate results be printed

Value

ggrep

grep output, with line numbers and pertaining line, or "No file with given string found".

grepnot

grep output, combination of invert=FALSE and =TRUE.

countChar

count the individual (if split=TRUE) characters in str

Note

ggrep, countChar: both use system( grep ...)
The composed file string and the input string to grep are shown for checking.
length(ggrep()) shows number of found entries only.
If file denotes a directory,and no "r" is given, then opt : contains e.g.
- "c": count lines in same one file only,
- "i": ignores case,
- "n": give file and line number,
- "r": recurse below directory one level (only),
- "v": inverts matches,
- "w": complete word matches only,
- "x": matches must be whole lines only
ggrep("-v","xxx",exclude="") is the same as
ggrep(,"",exclude="xxx"), except that the former lacks line numbers.

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
  length(ggrep("cnr","pad ",,"test*/*") )   # (dir), 10 files, not shown
  ggrep("cnr","pad ",,"test*/*")     # is dir, 10 files visited
  ggrep("cr","n2str",,"test/")
# /Users/hoffmannc/R/test/  may be a directory
# grep: /Users/hoffmannc/R/test/: No such file or directory
# NA

## End(Not run)

Example output

Loading required package: lattice
Loading required package: grid
test*/*  may be a directory
grep: test*/*: No such file or directory
[1] 1
test*/*  may be a directory
grep: test*/*: No such file or directory
[1] NA
test/  may be a directory
grep: test/: No such file or directory
[1] NA

cwhmisc documentation built on May 1, 2019, 7:55 p.m.