<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cerebral Mastication &#187; twitter</title>
	<atom:link href="http://www.cerebralmastication.com/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cerebralmastication.com</link>
	<description>Something to Chew On</description>
	<lastBuildDate>Fri, 16 Jul 2010 22:07:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Who&#039;s Tweets Do I Read&#8230; Magic R Code Says&#8230;</title>
		<link>http://www.cerebralmastication.com/2009/06/whos-tweets-do-i-read-magic-r-code-says/</link>
		<comments>http://www.cerebralmastication.com/2009/06/whos-tweets-do-i-read-magic-r-code-says/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:14:55 +0000</pubDate>
		<dc:creator>JD Long</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.cerebralmastication.com/?p=304</guid>
		<description><![CDATA[
So one glace at my user logs shows the truth: no one gives a rat&#8217;s rump that I just quit my job; you just love you some Twitter R code. And I&#8217;m nothing but an attention whore, so come get some!
So in my last &#8216;Twitter with R&#8217; post I gave you some code I&#8217;d written [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-303" title="tweetingme" src="http://www.cerebralmastication.com/wp-content/uploads/2009/06/tweetingme.png" alt="tweetingme" width="416" height="338" /></p>
<p>So one glace at my user logs shows the truth: no one gives a rat&#8217;s rump that<a href="http://www.cerebralmastication.com/?p=284"> I just quit my job</a>; you just <a href="http://www.cerebralmastication.com/?p=274">love you some Twitter R code</a>. And I&#8217;m nothing but an attention whore, so come get some!</p>
<p>So in my<a href="http://www.cerebralmastication.com/?p=274"> last &#8216;Twitter with R&#8217; post</a> I gave you some code I&#8217;d <span style="text-decoration: line-through;">written </span>ripped off that allowed you to update your status from R. That&#8217;s kinda cool, but really just for annoying your friends, tweeting when your code is finished running or, as Eva pointed out in the comments, maybe Tweeting the outcome of a routine. But R is good for analyzing data, plotting graphics, and cool stuff like that. Seems like under kill to just Tweet from it.</p>
<p>So let&#8217;s make some pretty pictures and stuff. Or more specifically, let&#8217;s plot a histogram of the last 200 Tweets you received and the people who sent them. An example of said histogram is above.</p>
<p>If you don&#8217;t already have the libraries XML, lattice, and RCurl, you will need them:<br />
<code>install.packages('RCurl')<br />
install.packages('XML')<br />
install.packages('lattice')</code></p>
<p>Then once you get those bad boys, you can run this code:</p>
<p><code>library("RCurl")<br />
library("XML")<br />
library("lattice")<br />
#<br />
#be sure and put your username and passy here<br />
username&lt;-"YourUserName"<br />
passy&lt;-"YourPass"<br />
#<br />
#This sets up the options for curl<br />
#then makes the request from the Twitter API<br />
#the count=200 option pulls the last 200 tweets from your friends<br />
#the twitter api limits you to a max of 200.... yeah, well that's life<br />
#<br />
opts &lt;- curlOptions(header = FALSE, userpwd = paste(username,":",passy,sep=""))<br />
request &lt;- "http://twitter.com/statuses/friends_timeline.xml?count=200"<br />
timeline &lt;- getURL(request,.opts = opts)<br />
#<br />
#Now let's beat up on the XML like it owes us money<br />
doc &lt;- xmlInternalTreeParse(timeline, useInternalNodes = TRUE)<br />
#<br />
#grab only the screen_names and make a list<br />
xml_names_of_posters &lt;- getNodeSet(doc, "/statuses/status/user/screen_name")<br />
text_names_of_posters &lt;- lapply(xml_names_of_posters,xmlValue)<br />
#<br />
#let's take it out of a list... just for kicks<br />
Twitterbaters &lt;- unlist(text_names_of_posters)<br />
#<br />
#and shove it into a data frame... seems like going around my</code><code><br />
#ass to get to my elbow, but I want to put it in a table eventually<br />
#table is kinda like a cross tab. It calcs the frequency for me<br />
posters_list_df&lt;-as.data.frame(Twitterbaters)<br />
Tweets = table(posters_list_df)<br />
#<br />
#lets graph this monkey business with lattice<br />
#<br />
NiftyChart&lt;-barchart(~sort(Tweets), main=list("Who's Tweets Am I Getting?" ,cex=1),xlab=list("Number of Tweets",cex=1))<br />
NiftyChart<br />
update(NiftyChart, col="brown")<br />
#</code></p>
<p><strong>EDIT:</strong> Look in the comments for a great base graphics solution from Paolo. He makes the same graph without Lattice.</p>
<p><span style="color: #800000;"><strong>Now be sure and change the username and password </strong></span>then run that mofo. So now you have a pretty picture like the one I made above. Pretty slick, no?</p>
<p>Special credit goes to @gappy3000 who tipped me off to making this with Lattice instead of ggplot because of the difficulty sorting with ggplot. @HarlanH for helping me know that my struggles with ggplot were not of my own making but were systemic.</p>
<p>The Twitter syntax I hacked together is from the <a href="http://apiwiki.twitter.com/Twitter-API-Documentation" onclick="pageTracker._trackPageview('/outgoing/apiwiki.twitter.com/Twitter-API-Documentation?referer=');">Twitter API documentation</a>. Have fun! And come back later for more attenion whoring blogging from your&#8217;s truly, @CMastication.</p>
<p>BTW, the reason I didn&#8217;t structure this as a function is that you should be stepping through this one line at a time to figure out how it works. That&#8217;s just harder with a function. So I did this for your own good. One day you&#8217;ll thank me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cerebralmastication.com/2009/06/whos-tweets-do-i-read-magic-r-code-says/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Twitter from R&#8230; Sure, why not!</title>
		<link>http://www.cerebralmastication.com/2009/06/twitter-from-r-sure-why-not/</link>
		<comments>http://www.cerebralmastication.com/2009/06/twitter-from-r-sure-why-not/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 15:22:21 +0000</pubDate>
		<dc:creator>JD Long</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.cerebralmastication.com/?p=274</guid>
		<description><![CDATA[
So I have started following the #RStats tag in twitter. Prior to a week ago I had never Twitterbated so I thought I would give it a go since I am not one to shy away from new technology&#8230; much. I think of Twitter like a call in radio show where I get to cut [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="whale baby" src="http://www.bit-101.com/blog/wp-content/uploads/2008/07/whale.png" alt="" width="169" height="128" /><br />
So I have started following the #RStats tag in twitter. Prior to a week ago I had never Twitterbated so I thought I would give it a go since I am not one to shy away from new technology&#8230; much. I think of Twitter like a call in radio show where I get to cut off callers when they annoy me.</p>
<p>Well one of the interesting things I ran across was <a href="http://twitter.com/JoFrhwld/statuses/2012755202" onclick="pageTracker._trackPageview('/outgoing/twitter.com/JoFrhwld/statuses/2012755202?referer=');">this tweet </a>that pointed to <a href="http://pastie.org/367741" onclick="pageTracker._trackPageview('/outgoing/pastie.org/367741?referer=');">this page about posting tweets from R</a>.  The code example was missing a couple of things, so here&#8217;s the cleaned up version:</p>
<blockquote>
<pre class="textmate-source">
<pre class="sunburst"><span class="status-body"><span class="entry-content">install.packages("RCurl")
library("RCurl")</span></span>
<span class="meta meta_paragraph meta_paragraph_text">opts = curlOptions(header = FALSE, userpwd = "username:password", netrc = FALSE)
</span>
<span class="meta meta_paragraph meta_paragraph_text">update &lt;- function(status){
  method &lt;- "<span class="markup markup_underline markup_underline_link">http://twitter.com/statuses/update.xml?status=</span>"
  encoded_status &lt;- URLencode(status)
  request &lt;- paste(method,encoded_status,sep = "")
  postForm(request,.opts = opts)
}
update("My first tweet from R! @CMastication is my daddy! #RStats")
</span></pre>
</pre>
</blockquote>
<p>This is a pretty good, and fairly self explanatory example of how to use RCurl to spew out some data. Don&#8217;t be a scriptard and try to run this without changing &#8216;username&#8217; and &#8216;password.&#8217; If you do, I&#8217;m coming to your house and going to beat you with your own keyboard until you admit that I am, indeed, your daddy.</p>
<p>Am I planning on Tweeting from R? You have to be kidding. That&#8217;s just silly. But I might need to use RCurl again. Although for long running scripts I may very well put code at the end of my scripts that sends out a Tweet when the code has finished running. Waaaay easier than setting up email and trying to ensure it runs from EC2 as well as my home machine, etc. The more I think about that, the more I am sure I&#8217;m a friggin genius. And of course, on every one of my script completion tweets I&#8217;m going to use the #RStats tag so everyone in twitterland will know that I am amazing. And a prick. All at the same time. I&#8217;m complex like that.</p>
<p>Oh yeah, I&#8217;m @CMastication on Twitter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cerebralmastication.com/2009/06/twitter-from-r-sure-why-not/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
