grab_match: Get Elements Matching Between 2 Points

Description Usage Arguments Value Examples

View source: R/grab_match.R

Description

Use regexes to get all the elements between two points.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

## S3 method for class 'character'
grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

## S3 method for class 'list'
grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

## S3 method for class 'data.frame'
grab_match(
  x,
  from = NULL,
  to = NULL,
  from.n = 1,
  to.n = 1,
  text.var = TRUE,
  ...
)

Arguments

x

A character vector, data.frame, or list.

from

A regex to start getting from (if NULL defaults to the first element/row).

to

A regex to get up to (if NULL defaults to the last element/row).

from.n

If more than one element matches from this dictates which one should be used. Must be an integer up to the number of possible matches, 'first' (equal to 1), 'last' (the last match possible), or 'n' (the same as 'last').

to.n

If more than one element matches to this dictates which one should be used. Must be an integer up to the number of possible matches, 'first' (equal to 1), 'last' (the last match possible), or 'n' (the same as 'last').

text.var

The name of the text variable with matches. If TRUE grab_match tries to detect the text column.

...

Other arguments passed to grep, most notable is ignore.case.

Value

Returns a subset of the original data set.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
grab_match(DATA$state, from = 'dumb', to = 'liar')
grab_match(DATA$state, from = 'dumb')
grab_match(DATA$state, to = 'liar')
grab_match(DATA$state, from = 'no', to = 'the', ignore.case = TRUE)
grab_match(DATA$state, from = 'no', to = 'the', ignore.case = TRUE, 
    from.n = 'first', to.n = 'last')
grab_match(as.list(DATA$state), from = 'dumb', to = 'liar')

## Data.frame: attempts to find text.var
grab_match(DATA, from = 'dumb', to = 'liar')

textshape documentation built on May 29, 2021, 1:07 a.m.