provigrep | R Documentation |
case-insensitive value-grep for a vector of patterns
case-insensitive grep for a vector of patterns
provigrep(
patterns,
x,
maxValues = NULL,
sortFunc = c,
rev = FALSE,
returnType = c("vector", "list"),
ignore.case = TRUE,
value = TRUE,
...
)
proigrep(..., value = FALSE)
patterns |
|
x |
|
maxValues |
|
sortFunc |
|
rev |
|
returnType |
|
ignore.case |
|
value |
|
... |
additional arguments are passed to |
Purpose is to provide "progressive vigrep()",which is value-returning, case-insensitive grep, starting with an ordered vector of grep patterns. For example, it returns entries in the order they are matched, by the progressive use of grep patterns.
It is particularly good when using multiple grep patterns, since
grep()
does not accept multiple patterns as input. This function
also only returns the unique matches in the order they were matched,
which alleviates the need to run a series of grep()
functions
and collating their results.
It is mainly to allow for prioritized ordering of matching entries, where one would like certain matching entries first, followed by another set of matching entries, without duplication. For example, one might grep for a few patterns, but want certain pattern hits to be listed first.
Other jam grep functions:
grepls()
,
igrepHas()
,
igrepl()
,
igrep()
,
unigrep()
,
unvigrep()
,
vgrep()
,
vigrep()
# a rather comical example
# set up a test set with labels containing several substrings
set.seed(1);
testTerms <- c("robot","tree","dog","mailbox","pizza","noob");
testWords <- pasteByRow(t(combn(testTerms,3)));
# now pull out entries matching substrings in order
provigrep(c("pizza", "dog", "noob", "."), testWords);
# more detail about the sort order is shown with returnType="list"
provigrep(c("pizza", "dog", "noob", "."), testWords, returnType="list");
# rev=TRUE will reverse the order of the list
provigrep(c("pizza", "dog", "noob", "."), testWords, returnType="list", rev=TRUE);
provigrep(c("pizza", "dog", "noob", "."), testWords, rev=TRUE);
# another example showing ordering of duplicated entries
set.seed(1);
x <- paste0(
sample(letters[c(1,2,2,3,3,3,4,4,4,4)]),
sample(1:5));
x;
# sort by letter
provigrep(letters[1:4], x)
# show more detail about how the sort is performed
provigrep(letters[1:4], x, returnType="list")
# rev=TRUE will reverse the order of pattern matching
# which is most useful when "." is the last pattern:
provigrep(c(letters[1:3], "."), x, returnType="list")
provigrep(c(letters[1:3], "."), x, returnType="list", rev=TRUE)
# example demonstrating maxValues
# return in list format
provigrep(c("[ABCD]", "[CDEF]", "[FGHI]"), LETTERS, returnType="list")
# maxValues=1
provigrep(c("[ABCD]", "[CDEF]", "[FGHI]"), LETTERS, returnType="list", maxValues=1)
provigrep(c("[ABCD]", "[CDEF]", "[FGHI]"), LETTERS, returnType="list", maxValues=1, value=FALSE)
proigrep(c("[ABCD]", "[CDEF]", "[FGHI]"), LETTERS, maxValues=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.