keepWords: Keep a selection of words or letters

View source: R/keepWords.R

keepWordsR Documentation

Keep a selection of words or letters

Description

Select words or letters based on their position in character strings.

Usage

keepWords(
  str,
  slc = 1,
  collapse = " ",
  na.rm = FALSE,
  split_words = "[[:punct:][:space:]]+"
)

keepLetters(
  str,
  slc = 1,
  collapse = "",
  na.rm = FALSE,
  rm_punct = "[[:punct:][:space:]]+"
)

keepInitials(str, split_words = "[\n\t\r\f\b[:punct:] ]+", collapse = "")

wordCount(str, split_words = "[[:punct:][:space:]]+")

Arguments

str

an input character vector (or a list) from which words will be extracted.

slc

a vector of integer indicating the selected positions of the words (or letters) to be kept.

collapse

character string used to separate selected words (or letters), if NULL, then selection is not collapsed and a list is returned.

na.rm

a logical. Should missing values be removed?

split_words

a character string containing a regular expression used to split words.

rm_punct

a character string containing a regular expression used to remove punctuation characters.

Value

A vector (or a list) of the selected words.

Functions

  • keepLetters(): A vector (or a list) of the selected letters.

  • keepInitials(): A vector (or a list) of initials.

  • wordCount(): A vector of the number of words for every character strings passed as an input.

See Also

strsplit()

Examples

keepWords(loremIpsum(), 1:3)
keepWords(c(loremIpsum(),'Another character string!'), slc = c(1,4))
keepWords(c(loremIpsum(),'A second character string.'), slc = c(1,4),
 na.rm = TRUE, collapse = '/')
strex <- c('Lorem ipsum', 'dolor sit', ' amet;')
keepLetters(strex, c(1,4))
keepLetters(strex, c(1,4), collapse = "")
keepInitials("National Basketball Association")
wordCount(c("two words!", "... and three words"))
wordCount(loremIpsum())

letiR/letiRmisc documentation built on Sept. 11, 2022, 12:43 a.m.