trunc_at {mclm} | R Documentation |
Truncate a sequence of character data
Description
This method takes as its argument x
an object that represents a sequence of
character data, such as an object of class tokens
, and truncates it at the
position where a match for the argument pattern
is found. Currently it is
only implemented for tokens
objects.
Usage
trunc_at(x, pattern, ...)
## S3 method for class 'tokens'
trunc_at(
x,
pattern,
keep_this = FALSE,
last_match = FALSE,
from_end = FALSE,
...
)
Arguments
x |
An object that represents a sequence of character data. |
pattern |
A regular expression. |
... |
Additional arguments. |
keep_this |
Logical. Whether the matching token itself should be kept.
If |
last_match |
Logical. In case there are several matching tokens, if
|
from_end |
Logical. If If |
Value
A truncated version of x
.
Examples
(toks <- tokenize('This is a first sentence . This is a second sentence .',
re_token_splitter = '\\s+'))
trunc_at(toks, re("[.]"))
trunc_at(toks, re("[.]"), last_match = TRUE)
trunc_at(toks, re("[.]"), last_match = TRUE, from_end = TRUE)