R Language

By default, R already has everything necessary to start using the pplapi.com API immediately. The basic code for loading a sample of agents into a data frame looks like this:

sample = read.csv("http://pplapi.com/batch/500/sample.csv")

Once you have your agents in a data frame, they behave exactly like any other data in R.

Plot Internet Access by Country

In this example, load a sample of 500 agents from pplAPI and plot Internet access by country.

sample = read.csv("http://pplapi.com/batch/500/sample.csv")
qplot(data=sample, country, fill=internet, stat="bin") +
    theme(axis.text.x = element_text(angle = 75, hjust = 1))

How to exceed the API limits with R

The API will return a maximum of 500 agents at once. Using a language like R, it is possible to repeatedly call the API while accumilating the results. In this manner, it is possible to build a data set of almost any size.

big_sample = data.frame()
for (i in seq(1, 10)) {
    sample = read.csv("http://pplapi.com/batch/500/sample.csv")
    big_sample = rbind(big_sample, sample)
    system("sleep 10")
write.csv(big_sample, "sample_5000.csv")

The above example will issue 10 API requests in order to accumulate n=5000 agents. The last line of this example will save the samples as a CSV called sample_5000.csv. Notice the usage of system("sleep 10"), which ensures our script will not exceed the API rate limits. If you do not include a pause like this, then the API will automatically block your requests until your quota replenishes.