Tuesday, 4 September 2012

R one-liners : do you have any to contribute?

NOT sure if installing packages to use one-liners count but heck .. anything to improve productivity eh?

excerpted from Jeffrey's blog http://jeffreybreen.wordpress.com/2011/07/21/one-liners-twitter/



One-liners which make me love R: twitteR’s searchTwitter() #rstats


R reminds me a lot of English. It’s easy to get started, but very difficult to master. So for all those times I’ve spent… well, forever… trying to figure out the “R way” of doing something, I’m glad to share these quick wins.
My recent R tutorial on mining Twitter for consumer sentiment wouldn’t have been possible without Jeff Gentry’s amazing twitteR package (available on CRAN). It does so much of the behind-the-scenes heavy lifting to access Twitter’s REST APIs, that one line of code is all you need to perform a search and retrieve the (even paginated) results:
library(twitteR)
tweets = searchTwitter("#rstats", n=1500)
You can search for anything, of course, “#rstats” is just an example. (And if you’re really into that hashtag, the twitteR package even provides an Rtweets() function which hardcodes that search string for you.) The n=1500 specifies the maximum number of tweets supported by the Search API, though you may retrieve fewer as Twitter’s search indices contain only a couple of days’ tweets.


No comments:

Post a Comment

Datanami, Woe be me