Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I love to have fun with R and Twitter…there are a lot of cool things that you can do with it…so I just thought of having a small Twitter Battle application…something that will grab the number of followers and lists from two users…apply some crappy algorithms and determine the Twitter importance between those users…using our .RData file that holds the Twitter OAuth info…

```require("Rook")
library("ROAuth")

setwd("C:/Blag/R_Scripts/Important_Scripts")

Get_Percentages<-function(p_one,p_two,flag){
if(p_one > p_two){
if(flag == 0){
OneFollowPercent<-100
TwoFollowPercent<-round((p_two * 100) / p_one)
}else{
TwoFollowPercent<-100 - (round((p_two * 100) / p_one))
if(TwoFollowPercent <= 49){
OneFollowPercent<-50 + TwoFollowPercent
TwoFollowPercent<-100 - OneFollowPercent
flag<-0
}else{
OneFollowPercent<-50 + TwoFollowPercent
TwoFollowPercent<-100 - TwoFollowPercent
TwoFollowPercent<-100 - round((round(TwoFollowPercent * 100) / OneFollowPercent))
OneFollowPercent<-TwoFollowPercent
TwoFollowPercent<-100 - OneFollowPercent
flag<-1
}
}
}
if(p_one < p_two){
if(flag == 0){
OneFollowPercent<-round((p_one * 100) / p_two)
TwoFollowPercent<-100
}else{
OneFollowPercent<-100 - (round((p_one * 100) / p_two))
if(OneFollowPercent <= 49){
TwoFollowPercent<-50 + OneFollowPercent
OneFollowPercent<-100 - TwoFollowPercent
flag<-0
}else{
TwoFollowPercent<-50 + OneFollowPercent
OneFollowPercent<-100 - OneFollowPercent
OneFollowPercent<-100 - round((round(OneFollowPercent * 100) / TwoFollowPercent))
TwoFollowPercent<-OneFollowPercent
OneFollowPercent<-100 - TwoFollowPercent
flag<-1
}
}
}
if(p_one == p_two){
OneFollowPercent<- 50
TwoFollowPercent<- 50
}
percents<-c(OneFollowPercent,TwoFollowPercent,flag)
return(percents)
}

newapp<-function(env){
req<-Rook::Request\$new(env)
res<-Rook::Response\$new()
res\$write('<form method="POST">\n')
res\$write('</BR>')
res\$write('</BR>')
res\$write('<input type="submit" name="Start the Battle!">')
res\$write('</form>')

if (!is.null(req\$POST())) {

GetYourFollowers<-GetYourUser\$followersCount
GetYourLists<-GetYourUser\$listedCount
GetHisHerFollowers<-GetHisHerUser\$followersCount
GetHisHerLists<-GetHisHerUser\$listedCount

FollowPercents<-Get_Percentages(GetYourFollowers,GetHisHerFollowers,0)
ListPercents<-Get_Percentages(GetYourLists,GetHisHerLists,0)

YourPercents<-FollowPercents[1] + ListPercents[1]
HisHerPercents<-FollowPercents[2] + ListPercents[2]

FinalPercents<-Get_Percentages(YourPercents,HisHerPercents,1)

YourPercents<-FinalPercents[1]
HisHerPercents<-FinalPercents[2]
if(FinalPercents[3] == 0){
DiffPercent<-abs(YourPercents - 50)
}else{
DiffPercent<-FinalPercents[1]
}

if(YourPercents > HisHerPercents){
res\$write(paste('<H1>',message,'</H1>'))
}
if(YourPercents < HisHerPercents){
res\$write(paste('<H1>',message,'</H1>'))
}
if(YourPercents == HisHerPercents){
res\$write(paste('<H1>',message,'</H1>'))
}

pieValues<-c(YourPercents,HisHerPercents)

dev.off()
res\$write("<div align='center'>")
res\$write(paste("<img src='", server\$full_url("pic"), "/",

res\$write("</div>")
}
res\$finish()
}

server = Rhttpd\$new()
server\$add(app = File\$new("C:/Blag/R_Scripts/Important_Scripts"), name = "pic")
server\$start()
```

When we execute it…we’re going to have some interesting results…

Have fun with it -;)

Greetings,

Blag.