[Rcpp-devel] wordcloud

ian.fellows at stat.ucla.edu ian.fellows at stat.ucla.edu
Sat Jul 23 18:02:08 CEST 2011


Hi all,

I've just released an R package to CRAN that creates pretty looking word
clouds. I think it makes a good minimal example of how to prototype an
algorithm in R, and then bring the performance bottleneck down to c++ to
improve speed.


An example:

>install.packages("wordcloud",repos="http://cran.r-project.org",type="source")
>library(tm)
>data(crude)
>crude <- tm_map(crude, removePunctuation)
>crude <- tm_map(crude, function(x)removeWords(x,stopwords()))
>tdm <- TermDocumentMatrix(crude)
>m <- as.matrix(tdm)
>v <- sort(rowSums(m),decreasing=TRUE)
>d <- data.frame(word = names(v),freq=v
+ )
>library(wordcloud)
Loading required package: Rcpp
>#using c++ to help layout the words
>system.time(wordcloud(d$word,d$freq,scale=c(8,.1),min.freq=0))
  user  system elapsed
 9.979   0.049   9.878
>#using R code to do the same layout
>system.time(wordcloud(d$word,d$freq,scale=c(8,.1),min.freq=0,use.r.layout=T))
  user  system elapsed
151.919   0.716 146.737

Cheers,
Ian



More information about the Rcpp-devel mailing list