Search code examples
rtextbibtexabbreviation

Convert string of words to a custom acronym/abbreviation in R and concatenate it with data from other rows?


Here is an example data set:

data <- data.frame (author = c('bob', 'john', 'james'), 
                    year = c(2000, 1942, 1765), 
                    title = c('test title one two three', 
                              'another test title four five', 
                              'third example title'))

And I would like to automate the process of making bibtex references, e.g. with a function like this:

bibtexify <- function (author, year, title) {
      acronym <- convert.to.acronym(title)
      paste(author, year, acronym, sep='')
      }

so that I get the following result:

with(data, bibtexify(author, year, title))
[1] 'bob2000tto'
[2] 'john1942att'
[3] 'james1765tet'

Is it possible to do this in R?


Solution

  • you want abbreviate

    R> abbreviate('test title one two three')
    test title one two three 
                 "ttott"