This month I got a chance to work with R and I must say it does wonders with almost no code, definitely a must try if you work with a lot of data and infographics. The existing packages and libraries are vast and cover almost all of the major APIs you would be working with. In the instructions below I was trying to work with the twitter APIs.
So here it goes, step by step instructions to get you started with R:
- Install R software from the link – https://cran.r-project.org/bin/windows/base/
- After installing R software, open the installed R GUI and then you would need the package that integrates R with Twitter. The library name is twitteR. To install this library, in the R interface you need to go to Packages->Install Packages->From the list select twitteR and click on Ok. Also install the package ‘bit64’ and ‘base64enc’ in case it’s not automatically installed, the exact same way as its mentioned before.
- So when you start working with R the first step that needs to be done is loading up the library that we are working with for which the one line syntax is:
library(twitteR) //This will load up the twitteR library that we would be using.
- The twitter APIs use OAuth for authentication for us to access their data. To get this firstly you need to create an application for yourself at https://twitter.com/apps/new. Here you will get your API key, API secret, Access token, Access secret and use the details in this command in the given format:
setup_twitter_oauth(“API key”, “API secret”,”Access token”,”Access secret”) //This would authenticate you to access twitter’s data for the active R session.
- r_tweets <- searchTwitter(“#chennaifloods”, n=300) //This would load up the tweets with the given hash tag here we are doing for Chennai floods and n signifies the number of tweets to be retrieved.
- head(tweets) // This would load up just the top 5-6 tweets from the tweets retrieved.
tweets // This would load up all the tweets from the tweets retrieve.
Example Sample for visualizations:
There is also a sample code below for doing visualizations with twitter data:
Loading required package: RCurl
Loading required package: bitops
Loading required package: RJSONIO
- result <- userTimeline(“BarackObama”, n=3200)
- df <- twListToDF(result)
- Created <- tweet.df$created
- counts <- table(as.Date(Created))[-1]
- dates <- as.Date(names(counts))
- # png(“twitteR-BarackPosts.png”, 650, 500)
- plot(dates, counts, type=”h”)
- # dev.off()
Let me know via the comments below if you get stuck anywhere.
The biggest question which got me stuck for more than 10 days was what sdk should be kept as the minimum targeted SDK, the basic difference between the different SDKs is the new functionalities they support which are not backward compatible without the usage of a support library or SDK. Definitely using a support library is extra work and when you are doing it solo avoid the extra work as much as possible but without any compromise with the quality of the final product. Moving on, to see which SDK, the most number of phones are running now you can visit the Android Dashboard @ https://developer.android.com/about/dashboards/index.html
It lists down everything clearly, the rough stats about the versions of android most phones are running currently, about the screen resolutions and also about the OpenGL support for when you are planning to develop graphics centered game or even app for that matter.
Recently I have started working with Android and have ran into a specific set of errors which I guess everyone will come across when they start working with Android. So the purpose of this post is to cover as many of those errors and also solutions to these errors.
- “Could not find FacebookSDK.apk!”
Steps to Reproduce – The project required the Facebook SDK which is available here. But when you try deploy the application on to a phone or a emulator, it throws the above error. The reason behind it is, when you import the SDK in your workspace as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device. [source]
Solution – Right Click on the project->Click on Project Properties->Under Android->Uncheck “Is Library” option->Clean and Build your project->Now try installing the library SDK
- “Session cannot be resolved to a type” | “The import.com.facebook cannot be resolved”
Steps to Reproduce – When you try to import a existing project in your workspace which has made use of Facebook libraries or APIs, the minute you start building it directly, the system will throw the above error.
Solution – Right Click on the project->Click on Project Properties->Under Android-> In references add the SDK project->Clean and Build your project->Now try building your project.
Sometimes this will still led to the same error, under those cases you might also have to do this:Right Click on the project->Click on Project Properties->Under Java build path-> In projects, add the SDK project->Clean and Build your project>Now try building your project
Tips & Tricks:
- Clean and Build your project – Do this whenever you make any property changes anywhere in the project
I will keep updating this post from time to time but if you have come across some error which is not listed above and might be helpful for others, feel free to leave that in the comments below.