How to write API packages for R

Overview

Installation

DVLA is not yet on CRAN. To install, simply run the following in R.

devtools::install_github("daveyr/DVLA")

Usage

Documentation on functions and examples can be found on its Github page. Here’s a more involved example, where we loop through a vector of car registration numbers.

# DVLA API in action
# 
# library(DVLA)
#  i <- 1
#  dvla <- NULL
#  for(reg in unique(fleet$reg)){
#    df <- getDVLA(key, reg)
#    dvla <- rbindlist(list(dvla,df), fill = T)
#    i <- i + 1
#    Sys.sleep(0.2) # avoid rate limits
#  }
#  
#  complete <- fleet %>%
# 	left_join(dvla, by = c("reg" = "registrationNumber"))

Backend

So what is happening behind the scenes? How would one go about replicating this type of package for another API?