R/wordcloudlame.R

Defines functions wordcloudlame

Documented in wordcloudlame

#' Produces wordcloud from the output function
#'
#' @param df A dataframe generated by the scrapescholar function.
#' @return Wordcloud for \code{df}.
#' @examples
#' wordcloudlame(output)
wordcloudlame <- function(df){
  library(wordcloud)
  library(tm)
  library(SnowballC)

  excerpt = df$excerpt
  #save it as a corpus file - only the abstract excluding the keywords
  abstract_article <- VCorpus(VectorSource(excerpt))
  #transformations - in tm package this is done using the tm_map function
  #removing whitespace
  abstract_article %>% tm_map(stripWhitespace) -> abstract_article
  #removing stopwords
  abstract_article %>% tm_map(removeWords, stopwords("english")) -> abstract_article
  #stemming
  abstract_article %>% tm_map(stemDocument) -> abstract_article
  #Term-Document Matrices
  dtm <- DocumentTermMatrix(abstract_article) %>% removeSparseTerms(0.8)
  #convert into a matrix
  dtm <- as.matrix(dtm)
  dtm <- as.data.frame(dtm)
  #create vector for data passed to the wordcloud function
  wordclouddata <- apply(dtm, 2, sum)
  #create word
  wordcloud(names(wordclouddata), wordclouddata)
}
lubospernis/litreviewbuddy documentation built on May 28, 2019, 8:40 a.m.