In two previous posts (intro, data entry), I described a simple, quick and easy solution for recording newborn feedings, dirty diapers and just about anything of interest. Here’s the second part of the implementation: the data analysis.
With all the data being logged on a Twitter feed, we'll be using R to extract the data for analysis.
Step 1: Install R
In order to do the data analysis in R, we will need to install R. 🙂 If you're not already familiar with R, it's a language and environment for statistical computing and graphics. Go to R Project, pick a mirror and download R for your OS and install it.
Step 2: Install RStudio
Although R is mature, RStudio is an awesome IDE that sits on top of R. It provides a lot of useful things like code completion, integrated plot pane, integrated help pane, list of variables, a view of both your R code and the REPL console, and much more! RStudio is certainly not necessary to run R, but you'll definitely be missing out. Install it now from the RStudio link!
Step 3: Get OAuth keys
In order to access Twitter from R, you'll need give our data analysis script access to Twitter via OAuth. If you're interested in the basics of OAuth, check out my OAuth post. The basics of what we're doing is using OAuth to authenticate our data analysis script so that we can access any Twitter feed. Since OAuth is being used, no passwords are disclosed. Instead of using an access token which is generally used for our customer, we'll be using the the consumer key (API Key), consumer secret (API Secret), access token and access secret to access Twitter from R.
- Navigate to Twitter Application Management.
- Click Create New App.
- Enter all the relevant details.
- Click Create your Twitter application.
- Navigate to the Keys and Access Tokens tab.
- You will find the Consumer API Key, Secret, Access Token and Access Secret.
Step 4: Plug them into the R script
Download the newborn-app.R script. With the Consumer API Key, Secret, Access Token and Access Secret, plug them into the script around lines 174-178.
Step 5: Execute the R script
Launch RStudio and load the R script with your changes. Then run the script.
Voila! Feeding stats at your fingertips.