The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis 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 into an R DataFrame.
library(jsonlite)
library(RCurl)
## Loading required package: bitops
library(stringr)
library(tidyverse)
## -- Attaching packages ----------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1 v readr 1.3.1
## v tibble 2.1.3 v purrr 0.3.2
## v tidyr 1.0.0 v dplyr 0.8.3
## v ggplot2 3.2.1 v forcats 0.4.0
## -- Conflicts -------------------------------------------------- tidyverse_conflicts() --
## x tidyr::complete() masks RCurl::complete()
## x dplyr::filter() masks stats::filter()
## x purrr::flatten() masks jsonlite::flatten()
## x dplyr::lag() masks stats::lag()
library(DT)
Load in the url.
url<-("https://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json?api-key=Mject8tCsAasZekK2jbUJb2T72KDuMe6")
1)Using jsonlite to load in the url. 2)Return it into a dataframe. 3)Create a list-columns of the dataframe of one of the columns, results.isbns. 4)Select the columns we have interest in: Title, description, author, and publisher. 5)Remove results. from each column name.
df_books<- fromJSON(url) %>%
as.data.frame() %>%
select(4, 5, 7, 11)
names(df_books) <- str_replace_all(names(df_books), "results.", "")
datatable(df_books)