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(DT)
## Warning: package 'DT' was built under R version 3.5.3
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 3.5.3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(RCurl)
## Loading required package: bitops
library(rjson)
library(RJSONIO)
##
## Attaching package: 'RJSONIO'
## The following objects are masked from 'package:rjson':
##
## fromJSON, toJSON
library(jsonlite)
##
## Attaching package: 'jsonlite'
## The following objects are masked from 'package:RJSONIO':
##
## fromJSON, toJSON
## The following objects are masked from 'package:rjson':
##
## fromJSON, toJSON
library(httr)
library(stringr)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
library(jsonlite)
library(httr)
Set API Key
apikey <- "N0kJIGXMAFAshBqvy9DQSEHG1IVArmH6"
Get the data
# make the url
url <- paste0("https://api.nytimes.com/svc/books/v3//lists/current/hardcover-fiction.json?api-key=",apikey)
fictionbooks <- GET(url)
fictionbooks$status_code
## [1] 200
Convert to data frame
fictiondf <- fromJSON(url, flatten = TRUE)
fictiondf <- fictiondf$results
fictiondf <- fictiondf$books
#datatable(fictiondf)
jsonR <- tbl_df(as.data.frame(fictiondf))
jsonR %>% kable() %>%
kable_styling(bootstrap_options = "striped", font_size = 10) %>%
scroll_box(height = "500px", width = "100%")
| rank | rank_last_week | weeks_on_list | asterisk | dagger | primary_isbn10 | primary_isbn13 | publisher | description | price | title | author | contributor | contributor_note | book_image | book_image_width | book_image_height | amazon_product_url | age_group | book_review_link | first_chapter_link | sunday_review_link | article_chapter_link | isbns | buy_links |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 29 | 0 | 0 | 0735219095 | 9780735219090 | Putnam | A woman who survived alone in the marsh becomes a murder suspect. | 0 | WHERE THE CRAWDADS SING | Delia Owens | by Delia Owens | https://s1.nyt.com/du/books/images/9780735219090.jpg | 328 | 495 | https://www.amazon.com/Where-Crawdads-Sing-Delia-Owens/dp/0735219095?tag=NYTBS-20 | list(isbn10 = c(“0735219095”, “0735219117”, “0525640371”), isbn13 = c(“9780735219090”, “9780735219113”, “9780525640370”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780735219090?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780735219090”, “https://www.amazon.com/Where-Crawdads-Sing-Delia-Owens/dp/0735219095?tag=NYTBS-20”)) | ||||||
| 2 | 0 | 1 | 0 | 0 | 1538748460 | 9781538748466 | Grand Central | A family is torn apart when the daughter becomes addicted to drugs and goes missing. | 0 | RUN AWAY | Harlan Coben | by Harlan Coben | https://s1.nyt.com/du/books/images/9781538748466.jpg | 328 | 495 | https://www.amazon.com/Run-Away-Harlan-Coben/dp/1538748460?tag=NYTBS-20 | list(isbn10 = “1538748460”, isbn13 = “9781538748466”) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781538748466?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781538748466”, “https://www.amazon.com/Run-Away-Harlan-Coben/dp/1538748460?tag=NYTBS-20”)) | ||||||
| 3 | 0 | 1 | 0 | 0 | 0735218994 | 9780735218994 | Putnam | The 25th book in the Dirk Pitt series. | 0 | CELTIC EMPIRE | Clive Cussler and Dirk Cussler | by Clive Cussler and Dirk Cussler | https://s1.nyt.com/du/books/images/9780735219007.jpg | 328 | 495 | https://www.amazon.com/Celtic-Empire-Dirk-Pitt-Adventure-ebook/dp/B079R3KT4X?tag=NYTBS-20 | list(isbn10 = c(“0735218994”, “0735219001”), isbn13 = c(“9780735218994”, “9780735219007”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780735218994?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780735218994”, “https://www.amazon.com/Celtic-Empire-Dirk-Pitt-Adventure-ebook/dp/B079R3KT4X?tag=NYTBS-20”)) | ||||||
| 4 | 2 | 2 | 0 | 0 | 0525538194 | 9780525538196 | Putnam | The Wyoming game wardens Joe Pickett and Katelyn Hamm take on killers working for the Sinaloa cartel. | 0 | WOLF PACK | CJ Box | by C.J. Box | https://s1.nyt.com/du/books/images/9780525538202.jpg | 328 | 495 | https://www.amazon.com/Wolf-Pack-Pickett-Novel-Book-ebook/dp/B07FLZYJD8?tag=NYTBS-20 | list(isbn10 = c(“0525538194”, “0525538208”), isbn13 = c(“9780525538196”, “9780525538202”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780525538196?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780525538196”, “https://www.amazon.com/Wolf-Pack-Pickett-Novel-Book-ebook/dp/B07FLZYJD8?tag=NYTBS-20”)) | ||||||
| 5 | 3 | 3 | 0 | 0 | 0062824619 | 9780062824615 | Morrow | The journalist Marshall McEwan returns to his hometown, which is shaken by two deaths and an economy on the brink. | 0 | CEMETERY ROAD | Greg Iles | by Greg Iles | https://s1.nyt.com/du/books/images/9780062824639.jpg | 328 | 495 | https://www.amazon.com/Cemetery-Road-Novel-Greg-Iles-ebook/dp/B07B7L4QMF?tag=NYTBS-20 | list(isbn10 = c(“0062824619”, “0062824635”, “006282466X”), isbn13 = c(“9780062824615”, “9780062824639”, “9780062824660”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780062824615?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780062824615”, “https://www.amazon.com/Cemetery-Road-Novel-Greg-Iles-ebook/dp/B07B7L4QMF?tag=NYTBS-20”)) | ||||||
| 6 | 4 | 3 | 0 | 0 | 1524798622 | 9781524798628 | Ballantine | A fictional oral history charting the rise and fall of a 70s rock n roll band. | 0 | DAISY JONES & THE SIX | Taylor Jenkins Reid | by Taylor Jenkins Reid | https://s1.nyt.com/du/books/images/9781524798628.jpg | 325 | 495 | https://www.amazon.com/Daisy-Jones-Taylor-Jenkins-Reid/dp/1524798622?tag=NYTBS-20 | https://www.nytimes.com/2019/03/04/books/review/daisy-jones-six-taylor-jenkins-reid.html | list(isbn10 = c(“1524798622”, “1524798630”, “1984892258”), isbn13 = c(“9781524798628”, “9781524798635”, “9781984892256”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781524798628?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781524798628”, “https://www.amazon.com/Daisy-Jones-Taylor-Jenkins-Reid/dp/1524798622?tag=NYTBS-20”)) | |||||
| 7 | 5 | 7 | 0 | 0 | 1250301696 | 9781250301697 | Celadon | Theo Faber looks into the mystery of a famous painter who stops speaking after shooting her husband. | 0 | THE SILENT PATIENT | Alex Michaelides | by Alex Michaelides | https://s1.nyt.com/du/books/images/9781250301697.jpg | 326 | 495 | https://www.amazon.com/Silent-Patient-Alex-Michaelides/dp/1250301696?tag=NYTBS-20 | list(isbn10 = c(“1250301696”, “1250301718”, “1250317541”), isbn13 = c(“9781250301697”, “9781250301710”, “9781250317544”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781250301697?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781250301697”, “https://www.amazon.com/Silent-Patient-Alex-Michaelides/dp/1250301696?tag=NYTBS-20”)) | ||||||
| 8 | 9 | 3 | 0 | 0 | 1501154850 | 9781501154850 | Scribner | The friendship over many decades of two female divers from the Korean Island of Jeju is pushed to a breaking point. | 0 | THE ISLAND OF SEA WOMEN | Lisa See | by Lisa See | https://s1.nyt.com/du/books/images/9781501154850.jpg | 328 | 495 | https://www.amazon.com/Island-Sea-Women-Novel/dp/1501154850?tag=NYTBS-20 | list(isbn10 = c(“1501154850”, “1501154877”), isbn13 = c(“9781501154850”, “9781501154874”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781501154850?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781501154850”, “https://www.amazon.com/Island-Sea-Women-Novel/dp/1501154850?tag=NYTBS-20”)) | ||||||
| 9 | 6 | 3 | 0 | 0 | 0399179380 | 9780399179389 | Delacorte | After tragedy strikes, a child TV star loses her memory and ability to speak. | 0 | SILENT NIGHT | Danielle Steel | by Danielle Steel | https://s1.nyt.com/du/books/images/9780399179396.jpg | 325 | 495 | https://www.amazon.com/Silent-Night-Novel-Danielle-Steel-ebook/dp/B07DN22MKB?tag=NYTBS-20 | list(isbn10 = c(“0399179380”, “0399179399”, “1984884573”), isbn13 = c(“9780399179389”, “9780399179396”, “9781984884572”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780399179389?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780399179389”, “https://www.amazon.com/Silent-Night-Novel-Danielle-Steel-ebook/dp/B07DN22MKB?tag=NYTBS-20”)) | ||||||
| 10 | 7 | 5 | 0 | 0 | 0316453307 | 9780316453301 | Little, Brown | Caleb Rooney, a police detective and celebrity food truck chef, must clear his name of murder allegations. | 0 | THE CHEF | James Patterson with Max DiLallo | by James Patterson with Max DiLallo | https://s1.nyt.com/du/books/images/9780316530002.jpg | 318 | 495 | https://www.amazon.com/Chef-James-Patterson-ebook/dp/B07HWPRDHM?tag=NYTBS-20 | list(isbn10 = c(“0316453307”, “031653000X”, “0316532320”), isbn13 = c(“9780316453301”, “9780316530002”, “9780316532327”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780316453301?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780316453301”, “https://www.amazon.com/Chef-James-Patterson-ebook/dp/B07HWPRDHM?tag=NYTBS-20”)) | ||||||
| 11 | 8 | 6 | 0 | 0 | 0062358200 | 9780062358202 | Morrow | A family crisis tests the bonds and ideals of a renowned poet and her siblings. | 0 | THE LAST ROMANTICS | Tara Conklin | by Tara Conklin | https://s1.nyt.com/du/books/images/9780062358202.jpg | 328 | 495 | https://www.amazon.com/Last-Romantics-Novel-Tara-Conklin/dp/0062358200?tag=NYTBS-20 | list(isbn10 = c(“0062358200”, “0062358227”, “0062887548”), isbn13 = c(“9780062358202”, “9780062358226”, “9780062887542”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780062358202?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780062358202”, “https://www.amazon.com/Last-Romantics-Novel-Tara-Conklin/dp/0062358200?tag=NYTBS-20”)) | ||||||
| 12 | 14 | 11 | 1 | 0 | None | 9781250314208 | St. Martin’s | Jessica Farriss life unravels when she signs up for Dr. Shieldss psychology study. | 0 | AN ANONYMOUS GIRL | Greer Hendricks and Sarah Pekkanen | by Greer Hendricks and Sarah Pekkanen | https://s1.nyt.com/du/books/images/9781250133731.jpg | 326 | 495 | https://www.amazon.com/Girl-Greer-Hendricks/dp/1250133734?tag=NYTBS-20 | list(isbn10 = c(“1250133734”, “1250133742”), isbn13 = c(“9781250133731”, “9781250133748”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781250314208?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781250314208”, “https://www.amazon.com/Girl-Greer-Hendricks/dp/1250133734?tag=NYTBS-20”)) | ||||||
| 13 | 11 | 3 | 0 | 0 | None | 9781250239723 | Minotaur | The 14th book in the Cotton Malone series. The former Justice Department operative tangles with a rogue cardinal and an ancient sect of knights. | 0 | THE MALTA EXCHANGE | Steve Berry | by Steve Berry | https://s1.nyt.com/du/books/images/9781250140272.jpg | 326 | 495 | https://www.amazon.com/Malta-Exchange-Novel-Cotton-Malone-ebook/dp/B07D2BV7LW?tag=NYTBS-20 | list(isbn10 = c(“1250140269”, “1250140277”), isbn13 = c(“9781250140265”, “9781250140272”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9781250239723?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781250239723”, “https://www.amazon.com/Malta-Exchange-Novel-Cotton-Malone-ebook/dp/B07D2BV7LW?tag=NYTBS-20”)) | ||||||
| 14 | 12 | 22 | 0 | 0 | 0385544154 | 9780385544153 | Doubleday | A decorated World War II veteran shoots and kills a pastor. | 0 | THE RECKONING | John Grisham | by John Grisham | https://s1.nyt.com/du/books/images/9780385544160.jpg | 326 | 495 | https://www.amazon.com/Reckoning-Novel-John-Grisham-ebook/dp/B079DBS447?tag=NYTBS-20 | list(isbn10 = c(“0385544154”, “0385544162”, “052563925X”, “0525639292”, “0385544170”), isbn13 = c(“9780385544153”, “9780385544160”, “9780525639251”, “9780525639299”, “9780385544177”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780385544153?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780385544153”, “https://www.amazon.com/Reckoning-Novel-John-Grisham-ebook/dp/B079DBS447?tag=NYTBS-20”)) | ||||||
| 15 | 0 | 14 | 0 | 0 | 0316556343 | 9780316556347 | Little, Brown | Zeus banishes Helios’ daughter to an island, where she must choose between living with gods or mortals. | 0 | CIRCE | Madeline Miller | by Madeline Miller | https://s1.nyt.com/du/books/images/9780316556347.jpg | 319 | 495 | https://www.amazon.com/Circe-Madeline-Miller/dp/0316556343?tag=NYTBS-20 | https://www.nytimes.com/2018/05/28/books/review/circe-madeline-miller.html | list(isbn10 = c(“0316556343”, “0316556335”, “1478975318”, “1549171763”, “1549142380”, “0316556327”), isbn13 = c(“9780316556347”, “9780316556330”, “9781478975311”, “9781549171765”, “9781549142383”, “9780316556323”)) | list(name = c(“Local Booksellers”, “Barnes and Noble”, “Amazon”), url = c(“http://www.indiebound.org/book/9780316556347?aff=NYT”, “http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780316556347”, “https://www.amazon.com/Circe-Madeline-Miller/dp/0316556343?tag=NYTBS-20”)) |
The New York Times Book Review API is a weekly paper-magazine supplement to The New York Times in which current non-fiction and fiction books are reviewed. It is one of the most influential and widely read book review publications in the industry that lets users to get book reviews displayed by ISBN,name of author and title