abbreviate: Abbreviate strings or tokens

Description Usage Arguments Details Value See Also Examples

View source: R/abbreviate.R

Description

Abbreviates strings by (optionally) tokenizing and matching token against a dictionary

Usage

1
2
abbreviate(string, dict = getOption("abbreviations", abbreviations),
  tokenizer = NULL)

Arguments

string

character; string to attempt to abbreviate

dict

dictionary-like object; uses global options 'confirm.abbreviations' or else the abbreviations

tokenizer

character; pattern passed to str_split to split strings with, usually '_' or ' '. If NULL, the default, strings will not be split.

Details

abbreviate works by first finding a list of tokens that occur in the code.

x can be adorned with match modifiers to control the type of match. See lookup for details.

If there is no matching entry for the token in the dictinary, no substitution is used.

Value

character; string with elements matching dict replaced

See Also

lookup
abbreviations
str_split

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  string <- c( 'foo bar', 'foo amount', 'amount', 'amount count date' )
   
  # Attempts to abreviate entire string
  abbreviate(string)
    
  # Tokenizes sting and matches against the token
  abbreviate(string, tokenizer=" ")
  
  abbreviate( c('product_year', "dollar_range"), abbreviations, tokenizer = '_')
  

decisionpatterns/conformist documentation built on Nov. 4, 2019, 10:23 a.m.