The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs.\ You'll need to start by signing up for an API key. Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it to an R dataframe.
library(tidyverse)
library(jsonlite)
library(DT)
library(RCurl)
library(stringr)
I decided to use the Book API,located at https://developer.nytimes.com/books_api.json, which has data on the Times' best-sellers list.
# Base url:
base.url <- "https://api.nytimes.com/svc/books/v3/"
recent.best.url <- "lists/best-sellers/history.json?"
recent.get <- getURL(recent.url)
This is in a pretty ugly, unreadable format, so let's clean it up.
recent.clean <- fromJSON(recent.get) %>%
as.data.frame() %>%
unnest(results.isbns) %>%
select(2, 4, 5, 7, 11:13)
names(recent.clean) <- str_replace_all(names(recent.clean), "results.", "")
datatable(recent.clean)