Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ggrep

Convenience functions for grep


Description

Grepping in a (my) R directory

Usage

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

## 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)

cwhmisc

Miscellaneous Functions for Math, Plotting, Printing, Statistics, Strings, and Tools

v6.6
GPL (>= 2)
Authors
Christian W. Hoffmann
Initial release
2018-08-24, 10:40:10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.