Cookies help us display personalized product recommendations and ensure you have great shopping experience.

By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SmartData CollectiveSmartData Collective
  • Analytics
    AnalyticsShow More
    business using business intelligence
    How to Use a Competitive Intelligence Dashboard to Turn Market Data Into Smarter Marketing Decisions 
    9 Min Read
    unusual trading activity
    Signal Or Noise? A Decision Tree For Evaluating Unusual Trading Activity
    3 Min Read
    software developer using ai
    How Data Analytics Helps Developers Deliver Better Tech Services
    8 Min Read
    ai for stock trading
    Can Data Analytics Help Investors Outperform Warren Buffett
    9 Min Read
    media monitoring
    Signals In The Noise: Using Media Monitoring To Manage Negative Publicity
    5 Min Read
  • Big Data
  • BI
  • Exclusive
  • IT
  • Marketing
  • Software
Search
© 2008-25 SmartData Collective. All Rights Reserved.
Reading: Tweeting from R
Share
Notification
Font ResizerAa
SmartData CollectiveSmartData Collective
Font ResizerAa
Search
  • About
  • Help
  • Privacy
Follow US
© 2008-23 SmartData Collective. All Rights Reserved.
SmartData Collective > Big Data > Data Mining > Tweeting from R
Data Mining

Tweeting from R

DavidMSmith
DavidMSmith
4 Min Read
SHARE

Over at Cerebral Mastication, you can find the code for a function that will allow you to send a status update to Twitter directly from the R console. The code’s pretty short, so here it is in full:

library(“RCurl”)
opts <->curlOptions(header = FALSE, 
  userpwd = “username:password”, netrc = FALSE)

tweet <->function(status){
  method <->“http://twitter.com/statuses/update.xml?status=”
  encoded_status <->URLencode(status)
  request <->paste(method,encoded_status,sep = “”)
  postForm(request,.opts = opts)
}

With this function, you can send a tweet simply by using the update function:

tweet(“This tweet comes from R! #rstats”)

(CM called the function update, but that overloads an existing function in R.) Now, you may be asking yourself, “Why would anyone want to do this?”. And it’s an excellent question: why use the R console when there are plenty of good applications that interface with Twitter already? But consider: what if you had an automated R application running in production, and needed to alert a large number of users when an event occurs: a long simulation has completed, a stock reaches a predetermined price, a chemical assay has detected a compound of interest. Now, …

Over at Cerebral Mastication, you can find the code for a function that will allow you to send a status update to Twitter directly from the R console. The code’s pretty short, so here it is in full:

More Read

Electronic textiles (e-textiles) are fabrics that have…
4 Best Practices for Sharing Workforce Data: Publishing Core Reports
“I think it is very likely that network infrastructure will be transformed in coming years by new…”
At the national level, making homes energy efficient is becoming…
Micro vs. Macro Information Retrieval

library(“RCurl”)
opts <- curlOptions(header = FALSE, 
  userpwd = “username:password”, netrc = FALSE)

tweet <- function(status){
  method <- “http://twitter.com/statuses/update.xml?status=”
  encoded_status <- URLencode(status)
  request <- paste(method,encoded_status,sep = “”)
  postForm(request,.opts = opts)
}

With this function, you can send a tweet simply by using the update function:

tweet(“This tweet comes from R! #rstats”)

(CM called the function update, but that overloads an existing function in R.) Now, you may be asking yourself, “Why would anyone want to do this?”. And it’s an excellent question: why use the R console when there are plenty of good applications that interface with Twitter already? But consider: what if you had an automated R application running in production, and needed to alert a large number of users when an event occurs: a long simulation has completed, a stock reaches a predetermined price, a chemical assay has detected a compound of interest. Now, with just a few lines of code and the RCurl package, you have a way of doing just that.

Cerebral Mastication: Twitter from R… Sure, Why Not!

Link to original post

Share This Article
Facebook Pinterest LinkedIn
Share

Follow us on Facebook

Latest News

business using business intelligence
How to Use a Competitive Intelligence Dashboard to Turn Market Data Into Smarter Marketing Decisions 
Analytics Big Data Exclusive Marketing
fda14abd c869 4da5 943c c036ad8efc2e
How Data-Driven Journalists Are Using API News Apps to Improve Reporting
Big Data Exclusive News
0622cae5 f7d7 4f74 84b5 eabd1a823dca
How Data-Driven Grocery Recommendations Help Shoppers Eat Better With Less Effort
Big Data Exclusive
business recovering from data loss
How Data-Driven Businesses Protect MySQL Databases from Shutdown
Big Data Exclusive

Stay Connected

1.2KFollowersLike
33.7KFollowersFollow
222FollowersPin

You Might also Like

Image
AnalyticsBig DataBusiness IntelligenceData MiningData WarehousingInside CompaniesModelingPolicy and GovernancePredictive AnalyticsPrivacySentiment AnalyticsSocial Media AnalyticsText AnalyticsUnstructured DataWeb Analytics

Facebook’s Big Data: Equal Parts Exciting and Terrifying?

8 Min Read

Predictive Analytics in the Cloud Research on SmartData Collective

2 Min Read
Image
Data Mining

Apache Spark Use Cases

6 Min Read

Welcome to the Retail Channel for the Business Intelligence…

1 Min Read

SmartData Collective is one of the largest & trusted community covering technical content about Big Data, BI, Cloud, Analytics, Artificial Intelligence, IoT & more.

data-driven web design
5 Great Tips for Using Data Analytics for Website UX
Big Data
ai is improving the safety of cars
From Bolts to Bots: How AI Is Fortifying the Automotive Industry
Artificial Intelligence

Quick Link

  • About
  • Contact
  • Privacy
Follow US
© 2008-25 SmartData Collective. All Rights Reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?