BurStMisc (version 1.1)

scriptSearch: Search R scripts for text

Description

Returns a list of text matches in the scripts in a directory.

Usage

scriptSearch(pattern, path = ".", subdirs = TRUE, suffix = "\\.[rR]$", commentsIncluded = FALSE, ..., verbose = FALSE)

Arguments

pattern
character string containing a regular expression (this is the argument of the same name for grep).
path
a character string giving the (relative) path of the directory holding the R scripts.
subdirs
logical value: if TRUE, then subdirectories of path are also searched.
suffix
a character string restricting the files to be searched.
commentsIncluded
logical value: if FALSE, then lines beginning with the hash symbol are ignored.
...
additional arguments to grep may be given -- the most likely possibilities are ignore.case, perl and fixed.
verbose
logical value: if TRUE, then the names of the scripts being searched are printed. The full name of this argument needs to be given -- no abbreviation is allowed.

Value

a list: the names are equal to the file names containing matches, and each component is a character vector of the whitespace-trimmed lines in the file that match the pattern.

Limitations

Using commentsIncluded=FALSE does not preclude a match being declared when it is in a comment not starting the line.

Details

The default suffix argument restricts the search to R scripts. An R script is considered to be a file that ends in dot-R, where the "R" can be lowercase or uppercase.

See Also

grep

Examples

Run this code
## Not run: 
# scriptSearch("list.files")
# scriptSearch("garch", "~/../burns-stat3/webpages/blog")
# 
# # search for an assignment
# # ' *' means zero or more spaces
# scriptSearch("specialObject *<- ", "~/myScriptDirectory", subdirs=FALSE)
# 
# # search COBOL files
# scriptSearch("blah", suffix="\\.cbl$")
# 
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace