Code
library(tidyverse)
library(jsonlite)
library(gt)
nyt_api_key <- Sys.getenv("NYT_API_KEY")The objective of this assignment is to become familiar with the process of interacting with a public API within R, specifically the New York Times Developer Network, and to demonstrate how data retrieved from an API may be parsed and transformed into a usable data frame for analytical endeavors. In this case, the New York Times Books API will be utilized, which provides access to current and historical best-seller lists. The analysis will be centered around examining author presence within the lists, with the prevailing question being: Which authors appear most frequently on the New York Times best-seller list within a selected category?
The analytical approach will likely follow the steps outlined below.
Firstly, an account will be created on the New York Times Developer Network in order to obtain a valid API key. This key will then be stored securely as an environment variable to ensure that it is not hard-coded within the script.
Subsequently, a request will be made to the Books API endpoint, specifically the current best-seller list endpoint, by constructing the appropriate URL and passing the API key as a parameter.
Once the request has been made, the returned JSON response will be imported into R and parsed using the jsonlite package. Given that the Books API response contains nested elements, particularly within the “results” and “books” fields, the relevant components will then be extracted and flattened into the desired tabular structure.
Following this, the extracted data will be converted into a tidy data frame, retaining only the variables of interest such as title, author, rank, and weeks on the list. Any inconsistencies or missing values will have to be identified and addressed during this part of the transformation process.
Finally, the resulting data frame will be used to perform a simple aggregation in order to determine which authors appear most frequently within the selected best-seller list, thereby answering the afore-posed research question.
After an account was created for the NYT Developer Network, a novel app was created (data_607_week_nine) within which the Books API was enabled. Upon saving the app, we are now able to access an API key that will facilitate our linkage to the NYT Books API. This API key was then stored as an environment variable, which was consistent with both the assignment directives and standard practice.
Proceeding, the necessary libraries will be loaded in.
library(tidyverse)
library(jsonlite)
library(gt)
nyt_api_key <- Sys.getenv("NYT_API_KEY")For the scope of this assignment, the selected Books API will be the current Hardcover Fiction best-seller list. The Books API documentation describes the list detail service as a sort of request made to the list endpoint, using the list name and either a date or the term current.
nyt_books_url <- paste0(
"https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=", nyt_api_key
)The request can now be made, after which the derived JSON response can be imported into RStudio.
nyt_books_raw <- fromJSON(nyt_books_url)
glimpse(nyt_books_raw)List of 5
$ status : chr "OK"
$ copyright : chr "Copyright (c) 2026 The New York Times Company. All Rights Reserved."
$ num_results : int 15
$ last_modified: chr "2026-03-25T22:37:48Z"
$ results :List of 12
..$ display_name : chr "Hardcover Fiction"
..$ list_name : chr "Hardcover Fiction"
..$ list_name_encoded : chr "hardcover-fiction"
..$ previous_published_date: chr "2026-03-29"
..$ published_date : chr "2026-04-05"
..$ bestsellers_date : chr "2026-03-21"
..$ normal_list_ends_at : int 15
..$ updated : chr "WEEKLY"
..$ list_id : int 1
..$ uri : chr "nyt://bestsellerslist/aa7d0d6a-4071-5737-ad6e-079ba050ef04"
..$ books :'data.frame': 15 obs. of 28 variables:
.. ..$ age_group : chr [1:15] "" "" "" "" ...
.. ..$ amazon_product_url : chr [1:15] "https://www.amazon.com/dp/0316579831?tag=thenewyorktim-20" "https://www.amazon.com/dp/0593798430?tag=thenewyorktim-20" "https://www.amazon.com/dp/1538743027?tag=thenewyorktim-20" "https://www.amazon.com/dp/125033781X?tag=thenewyorktim-20" ...
.. ..$ article_chapter_link: chr [1:15] "" "" "" "" ...
.. ..$ asterisk : int [1:15] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ author : chr [1:15] "Viola Davis and James Patterson" "Virginia Evans" "Sandra Brown" "Alice Feeney" ...
.. ..$ book_image : chr [1:15] "https://static01.nyt.com/bestsellers/images/9780316579834.jpg" "https://static01.nyt.com/bestsellers/images/9780593798430.jpg" "https://static01.nyt.com/bestsellers/images/9781538743027.jpg" "https://static01.nyt.com/bestsellers/images/9781250337818.jpg" ...
.. ..$ book_image_height : int [1:15] 500 0 500 0 500 0 500 500 400 400 ...
.. ..$ book_image_width : int [1:15] 322 0 331 0 313 0 327 331 312 312 ...
.. ..$ book_review_link : chr [1:15] "" "" "" "" ...
.. ..$ book_uri : chr [1:15] "nyt://book/6f72e477-90a5-5cbc-9f2d-d96c1590adeb" "nyt://book/ee6e7478-d847-5258-a579-f9ef0ed9c301" "nyt://book/2a0aead0-b991-5fcd-bead-d15428ad309d" "nyt://book/0461987c-33f3-5d5d-a2ad-f03226f1ca3a" ...
.. ..$ contributor : chr [1:15] "by Viola Davis and James Patterson" "by Virginia Evans" "by Sandra Brown" "by Alice Feeney" ...
.. ..$ contributor_note : chr [1:15] "" "" "" "" ...
.. ..$ created_date : chr [1:15] "2026-03-18T22:38:16.974Z" "2026-03-04T23:40:21.28Z" "2026-03-25T22:37:40.571Z" "2026-03-04T23:39:58.687Z" ...
.. ..$ dagger : int [1:15] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ description : chr [1:15] "Judge Mary Stone oversees an ethically complex case in her courtroom in Union Springs, Ala." "Letters from someone she used to know push Sybil Van Antwerp toward revisiting her past and finding a way to forgive." "The mutual attraction between Detective Mitch Haskell and his therapist may hinder his attempt to avenge his murdered wife." "In an old house in a seaside town, things may not be what they appear to be." ...
.. ..$ first_chapter_link : chr [1:15] "" "" "" "" ...
.. ..$ price : chr [1:15] "0.00" "0.00" "0.00" "0.00" ...
.. ..$ primary_isbn10 : chr [1:15] "" "" "" "" ...
.. ..$ primary_isbn13 : chr [1:15] "9780316579834" "9780593798430" "9781538743027" "9781250337818" ...
.. ..$ publisher : chr [1:15] "Little, Brown and JVL" "Crown" "Grand Central" "Pine & Cedar" ...
.. ..$ rank : int [1:15] 1 2 3 4 5 6 7 8 9 10 ...
.. ..$ rank_last_week : int [1:15] 1 3 0 8 0 5 0 4 7 12 ...
.. ..$ sunday_review_link : chr [1:15] "" "" "" "" ...
.. ..$ title : chr [1:15] "JUDGE STONE" "THE CORRESPONDENT" "BLOODLUST" "MY HUSBAND'S WIFE" ...
.. ..$ updated_date : chr [1:15] "2026-03-18T22:38:16.974Z" "2026-03-04T23:40:21.28Z" "2026-03-25T22:37:40.571Z" "2026-03-04T23:39:58.687Z" ...
.. ..$ weeks_on_list : int [1:15] 2 21 1 8 1 10 1 4 3 5 ...
.. ..$ isbns :List of 15
.. ..$ buy_links :List of 15
..$ corrections : list()
head(nyt_books_raw)$status
[1] "OK"
$copyright
[1] "Copyright (c) 2026 The New York Times Company. All Rights Reserved."
$num_results
[1] 15
$last_modified
[1] "2026-03-25T22:37:48Z"
$results
$results$display_name
[1] "Hardcover Fiction"
$results$list_name
[1] "Hardcover Fiction"
$results$list_name_encoded
[1] "hardcover-fiction"
$results$previous_published_date
[1] "2026-03-29"
$results$published_date
[1] "2026-04-05"
$results$bestsellers_date
[1] "2026-03-21"
$results$normal_list_ends_at
[1] 15
$results$updated
[1] "WEEKLY"
$results$list_id
[1] 1
$results$uri
[1] "nyt://bestsellerslist/aa7d0d6a-4071-5737-ad6e-079ba050ef04"
$results$books
age_group amazon_product_url
1 https://www.amazon.com/dp/0316579831?tag=thenewyorktim-20
2 https://www.amazon.com/dp/0593798430?tag=thenewyorktim-20
3 https://www.amazon.com/dp/1538743027?tag=thenewyorktim-20
4 https://www.amazon.com/dp/125033781X?tag=thenewyorktim-20
5 https://www.amazon.com/dp/0593722590?tag=thenewyorktim-20
6 https://www.amazon.com/dp/0593820266?tag=thenewyorktim-20
7 https://www.amazon.com/dp/1250405408?tag=thenewyorktim-20
8 https://www.amazon.com/dp/0525659188?tag=thenewyorktim-20
9 https://www.amazon.com/dp/1250439205?tag=thenewyorktim-20
10 https://www.amazon.com/dp/B094X214V9?tag=thenewyorktim-20
11 https://www.amazon.com/dp/0385548982?tag=thenewyorktim-20
12 https://www.amazon.com/dp/B0DQ72PKP2?tag=thenewyorktim-20
13 https://www.amazon.com/dp/0593851099?tag=thenewyorktim-20
14 https://www.amazon.com/dp/0593955978?tag=thenewyorktim-20
15 https://www.amazon.com/dp/B08V8877BY?tag=thenewyorktim-20
article_chapter_link asterisk author
1 0 Viola Davis and James Patterson
2 0 Virginia Evans
3 0 Sandra Brown
4 0 Alice Feeney
5 0 Ava Reid
6 0 Matt Dinniman
7 0 Carissa Broadbent
8 0 Tayari Jones
9 0 Christopher Buehlman
10 0 Matt Dinniman
11 0 John Grisham
12 0 SenLinYu
13 0 C.J. Box
14 0 Matt Dinniman
15 0 Matt Dinniman
book_image
1 https://static01.nyt.com/bestsellers/images/9780316579834.jpg
2 https://static01.nyt.com/bestsellers/images/9780593798430.jpg
3 https://static01.nyt.com/bestsellers/images/9781538743027.jpg
4 https://static01.nyt.com/bestsellers/images/9781250337818.jpg
5 https://static01.nyt.com/bestsellers/images/9780593722596.jpg
6 https://static01.nyt.com/bestsellers/images/9780593820261.jpg
7 https://static01.nyt.com/bestsellers/images/9781250405401.jpg
8 https://static01.nyt.com/bestsellers/images/9780525659181.jpg
9 https://static01.nyt.com/bestsellers/images/9781250439208.jpg
10 https://static01.nyt.com/bestsellers/images/9780593820285.jpg
11 https://static01.nyt.com/bestsellers/images/9780385548984.jpg
12 https://static01.nyt.com/bestsellers/images/9780593972700.jpg
13 https://static01.nyt.com/bestsellers/images/9780593851098.jpg
14 https://static01.nyt.com/bestsellers/images/9780593955970.jpg
15 https://static01.nyt.com/bestsellers/images/9780593820247.jpg
book_image_height book_image_width
1 500 322
2 0 0
3 500 331
4 0 0
5 500 313
6 0 0
7 500 327
8 500 331
9 400 312
10 400 312
11 0 0
12 0 0
13 500 332
14 500 331
15 400 312
book_review_link
1
2
3
4
5
6
7
8 https://www.nytimes.com/2026/02/19/books/review/kin-tayari-jones.html
9
10
11
12
13
14
15
book_uri
1 nyt://book/6f72e477-90a5-5cbc-9f2d-d96c1590adeb
2 nyt://book/ee6e7478-d847-5258-a579-f9ef0ed9c301
3 nyt://book/2a0aead0-b991-5fcd-bead-d15428ad309d
4 nyt://book/0461987c-33f3-5d5d-a2ad-f03226f1ca3a
5 nyt://book/be7ea6b9-7f6a-59f3-aae0-f19d20c8e552
6 nyt://book/e84133b7-b087-54fe-aa42-0605dff68e6f
7 nyt://book/9de5334b-3247-5c47-9651-8edffff957a9
8 nyt://book/aa33c150-8324-558d-b307-2e132de2ea01
9 nyt://book/51e94526-6db1-51fd-bdf1-31a295cb16b3
10 nyt://book/87acdbd7-b1e9-576a-a712-830df9715448
11 nyt://book/b4d35d23-bb5e-5f9c-b842-01c4352fe4dc
12 nyt://book/e9c567d8-7c38-5cb8-88e5-ba46078e2144
13 nyt://book/0c3b50f4-86ea-5c00-88d8-aa28a21d2035
14 nyt://book/253e5724-9547-5551-b50d-97d71cbcfa45
15 nyt://book/b684926b-80a9-5829-9c38-876d4d3382b7
contributor contributor_note created_date
1 by Viola Davis and James Patterson 2026-03-18T22:38:16.974Z
2 by Virginia Evans 2026-03-04T23:40:21.28Z
3 by Sandra Brown 2026-03-25T22:37:40.571Z
4 by Alice Feeney 2026-03-04T23:39:58.687Z
5 by Ava Reid 2026-03-25T22:37:40.835Z
6 by Matt Dinniman 2026-03-04T23:39:58.983Z
7 by Carissa Broadbent 2026-03-25T22:37:40.991Z
8 by Tayari Jones 2026-03-04T23:40:21.534Z
9 by Christopher Buehlman 2026-03-25T23:53:45.841Z
10 by Matt Dinniman 2026-03-25T22:37:41.16Z
11 by John Grisham 2026-03-04T23:39:59.118Z
12 by SenLinYu 2026-03-04T23:39:58.831Z
13 by C.J. Box 2026-03-04T23:39:58.173Z
14 by Matt Dinniman 2026-03-25T22:37:41.297Z
15 by Matt Dinniman 2025-10-22T22:37:44.854Z
dagger
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
description
1 Judge Mary Stone oversees an ethically complex case in her courtroom in Union Springs, Ala.
2 Letters from someone she used to know push Sybil Van Antwerp toward revisiting her past and finding a way to forgive.
3 The mutual attraction between Detective Mitch Haskell and his therapist may hinder his attempt to avenge his murdered wife.
4 In an old house in a seaside town, things may not be what they appear to be.
5 Passion and revenge fuel Agnes as she seeks to recapture her family’s honor.
6 The second book in the "Dungeon Crawler Carl" series. Carl and Donut confront an ancient spell and heightened dangers.
7 The third book in the War of Lost Hearts series. Tisaanah, Maxatarius and Aefe are caught in an upheaval between two worlds.
8 Vernice and Annie, two neighbors without mothers in Louisiana, go on divergent paths in life and are brought back together by tragedy.
9 In 1348, a disgraced knight shepherds an orphan of the Black Death and winds up on a battlefield of conflicting forces.
10 The third book in the "Dungeon Crawler Carl" series. Carl and Donut are up against a subway system filled with monsters.
11 When Simon Latch, a lawyer in rural Virginia, is accused of murder, he goes in search of the real killer.
12 After the war, an imprisoned alchemist is sent to a necromancer to recover her lost memories.
13 The 26th book in the Joe Pickett series. After Joe takes a gunshot to the head, his daughters seek to find out who did it.
14 The fourth book in the Dungeon Crawler Carl series. Obstacles abound on the fifth floor of the dungeon.
15 A Coast Guard vet named Carl and his ex-girlfriend’s cat, Princess Donut, are trapped in a fantasy dungeon.
first_chapter_link price primary_isbn10 primary_isbn13 publisher
1 0.00 9780316579834 Little, Brown and JVL
2 0.00 9780593798430 Crown
3 0.00 9781538743027 Grand Central
4 0.00 9781250337818 Pine & Cedar
5 0.00 9780593722596 Del Rey
6 0.00 9780593820261 Ace
7 0.00 9781250405401 Bramble
8 0.00 9780525659181 Knopf
9 0.00 9781250439208 Tor Nightfire
10 0.00 9780593820285 Ace
11 0.00 9780385548984 Doubleday
12 0.00 9780593972700 Del Rey
13 0.00 9780593851098 Putnam
14 0.00 9780593955970 Ace
15 0.00 9780593820247 Ace
rank rank_last_week sunday_review_link title
1 1 1 JUDGE STONE
2 2 3 THE CORRESPONDENT
3 3 0 BLOODLUST
4 4 8 MY HUSBAND'S WIFE
5 5 0 INNAMORATA
6 6 5 CARL'S DOOMSDAY SCENARIO
7 7 0 MOTHER OF DEATH AND DAWN
8 8 4 KIN
9 9 7 BETWEEN TWO FIRES
10 10 12 THE DUNGEON ANARCHIST'S COOKBOOK
11 11 10 THE WIDOW
12 12 11 ALCHEMISED
13 13 6 THE CROSSROADS
14 14 0 THE GATE OF THE FERAL GODS
15 15 0 DUNGEON CRAWLER CARL
updated_date weeks_on_list isbns
1 2026-03-18T22:38:16.974Z 2 , 9780316579834
2 2026-03-04T23:40:21.28Z 21 , 9780593798430
3 2026-03-25T22:37:40.571Z 1 , 9781538743027
4 2026-03-04T23:39:58.687Z 8 , 9781250337818
5 2026-03-25T22:37:40.835Z 1 , 9780593722596
6 2026-03-04T23:39:58.983Z 10 , 9780593820261
7 2026-03-25T22:37:40.991Z 1 , 9781250405401
8 2026-03-04T23:40:21.534Z 4 , 9780525659181
9 2026-03-25T23:53:45.841Z 3 , 9781250439208
10 2026-03-25T22:37:41.16Z 5 , 9780593820285
11 2026-03-04T23:39:59.118Z 22 , 9780385548984
12 2026-03-04T23:39:58.831Z 26 , 9780593972700
13 2026-03-04T23:39:58.173Z 4 , 9780593851098
14 2026-03-25T22:37:41.297Z 2 , 9780593955970
15 2025-10-22T22:37:44.854Z 12 , 9780593820247
buy_links
1 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0316579831?tag=thenewyorktim-20, https://goto.applebooks.apple/9780316579834?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780316579834&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fjudge-stone-james-patterson%2F1148464105%3Fean%3D9780316579834&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FJudge-Stone%2FJames-Patterson%2F9780316579834, https://bookshop.org/a/3546/9780316579834
2 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593798430?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593798430?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593798430&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-correspondent-virginia-evans%2F1146138272%3Fean%3D9780593798430&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fsearch%3Fquery%3DTHE%2520CORRESPONDENT%2520by%2520Virginia%2520Evans, https://bookshop.org/a/3546/9780593798430
3 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1538743027?tag=thenewyorktim-20, https://goto.applebooks.apple/9781538743027?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781538743027&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fbloodlust-sandra-brown%2F1114301748%3Fean%3D9781538743027&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FBloodlust%2FSandra-Brown%2F9781538743027, https://bookshop.org/a/3546/9781538743027
4 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/125033781X?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250337818?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781250337818&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fmy-husbands-wife-alice-feeney%2F1147242018%3Fean%3D9781250337818&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FMy-Husbands-Wife%2FAlice-Feeney%2F9781250337818, https://bookshop.org/a/3546/9781250337818
5 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593722590?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593722596?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593722596&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Finnamorata-ava-reid%2F1147669401%3Fean%3D9780593722596&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FInnamorata%2FAva-Reid%2F9780593722596, https://bookshop.org/a/3546/9780593722596
6 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593820266?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820261?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593820261&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fcarls-doomsday-scenario-matt-dinniman%2F1145070342%3Fean%3D9780593820261&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FCarls-Doomsday-Scenario%2FMatt-Dinniman%2F9780593820261, https://bookshop.org/a/3546/9780593820261
7 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1250405408?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250405401?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781250405401&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fmother-of-death-and-dawn-carissa-broadbent%2F1141041635%3Fean%3D9781250405401&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FMother-Death-Dawn%2FCarissa-Broadbent%2F9781250405401, https://bookshop.org/a/3546/9781250405401
8 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0525659188?tag=thenewyorktim-20, https://goto.applebooks.apple/9780525659181?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780525659181&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fkin-tayari-jones%2F1148177459%3Fean%3D9780525659181&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FKin%2FTayari-Jones%2F9780525659181, https://bookshop.org/a/3546/9780525659181
9 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1250439205?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250439208?at=10lIEQ, https://www.barnesandnoble.com/w/between-two-fires-christopher-buehlman/1108799136?ean=9781250439208, https://www.booksamillion.com/p/Between-Two-Fires/Christopher-Buehlman/9781250439208, https://bookshop.org/p/books/between-two-fires-christopher-buehlman/0f55d0b868b5b4f9?ean=9781250439208&next=t
10 Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B094X214V9?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820285?at=10lIEQ, https://www.barnesandnoble.com/w/the-dungeon-anarchists-cookbook-matt-dinniman/1145437166?ean=9780593820285, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDungeon-Anarchists-Cookbook%2FMatt-Dinniman%2F9780593820285, https://bookshop.org/a/3546/9780593820285
11 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0385548982?tag=thenewyorktim-20, https://goto.applebooks.apple/9780385548984?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780385548984&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-widow-john-grisham%2F1147191431%3Fean%3D9780385548984&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FWidow%2FJohn-Grisham%2F9780385548984, https://bookshop.org/a/3546/9780385548984
12 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B0DQ72PKP2?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593972717?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593972700&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Falchemised-senlinyu%2F1146838848%3Fean%3D9780593972700&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fsearch%3Fquery%3DALCHEMISED%2520by%2520SenLinYu, https://bookshop.org/a/3546/9780593972717
13 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593851099?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593851098?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593851098&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-crossroads-c-j-box%2F1147476791%3Fean%3D9780593851098&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FCrossroads%2FC-J-Box%2F9780593851098, https://bookshop.org/a/3546/9780593851098
14 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593955978?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593955970?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593955970&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-gate-of-the-feral-gods-matt-dinniman%2F1146460801%3Fean%3D9780593955970&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BGATE%2BOF%2BTHE%2BFERAL%2BGODS%2FMatt%2BDinniman%2F9780593955970, https://bookshop.org/a/3546/9780593955970
15 Amazon, Apple Books, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B08V8877BY?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820247?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDungeon-Crawler-Carl%2FMatt-Dinniman%2F9780593820247, https://bookshop.org/a/3546/9780593820247
$results$corrections
list()
The Books API returns a nested JSON structure, so the relevant fields must now be explored and extracted from the response.
names(nyt_books_raw)[1] "status" "copyright" "num_results" "last_modified"
[5] "results"
names(nyt_books_raw$results) [1] "display_name" "list_name"
[3] "list_name_encoded" "previous_published_date"
[5] "published_date" "bestsellers_date"
[7] "normal_list_ends_at" "updated"
[9] "list_id" "uri"
[11] "books" "corrections"
Now, the most relevant fields pertaining to the goal of this analysis will be extracted from the books list. These are: title, author, rank, publisher, weeks on list, the books’ ISBN numbers, as well as the book descriptions.
nyt_books_df <- nyt_books_raw$results$books %>%
as_tibble() %>%
select(
rank,
title,
author,
publisher,
weeks_on_list,
primary_isbn13,
description
) %>%
rename(isbn13 = primary_isbn13)
glimpse(nyt_books_df)Rows: 15
Columns: 7
$ rank <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
$ title <chr> "JUDGE STONE", "THE CORRESPONDENT", "BLOODLUST", "MY HUS…
$ author <chr> "Viola Davis and James Patterson", "Virginia Evans", "Sa…
$ publisher <chr> "Little, Brown and JVL", "Crown", "Grand Central", "Pine…
$ weeks_on_list <int> 2, 21, 1, 8, 1, 10, 1, 4, 3, 5, 22, 26, 4, 2, 12
$ isbn13 <chr> "9780316579834", "9780593798430", "9781538743027", "9781…
$ description <chr> "Judge Mary Stone oversees an ethically complex case in …
head(nyt_books_df)# A tibble: 6 × 7
rank title author publisher weeks_on_list isbn13 description
<int> <chr> <chr> <chr> <int> <chr> <chr>
1 1 JUDGE STONE Viola… Little, … 2 97803… "Judge Mar…
2 2 THE CORRESPONDENT Virgi… Crown 21 97805… "Letters f…
3 3 BLOODLUST Sandr… Grand Ce… 1 97815… "The mutua…
4 4 MY HUSBAND'S WIFE Alice… Pine & C… 8 97812… "In an old…
5 5 INNAMORATA Ava R… Del Rey 1 97805… "Passion a…
6 6 CARL'S DOOMSDAY SCENA… Matt … Ace 10 97805… "The secon…
At this stage, the Books API response has been converted into a tidy data frame, with one row corresponding to one book presently on the selected best-seller list.
In considering the prior data cleaning decisions that were executed, the initial returned JSON response was nested, so only the desired fields from the book component were extracted into the final data frame. Secondly, the ISBN field was renamed to “isbn13” for additional clarity. We will now move onto the analytical portion of this assignment.
Since Matt Dinniman was the author appearing the most times within the imported best-seller list for Hardcover Fiction, a further step in the analytical process could (and will) entail examining his book titles.
top_author <- author_frequency %>%
slice(1) %>%
pull(author)
top_author_books <- nyt_books_df %>%
filter(author == top_author) %>%
select(title, weeks_on_list, description) %>%
arrange(desc(weeks_on_list))
top_author_books# A tibble: 4 × 3
title weeks_on_list description
<chr> <int> <chr>
1 DUNGEON CRAWLER CARL 12 "A Coast Guard vet named Carl …
2 CARL'S DOOMSDAY SCENARIO 10 "The second book in the \"Dung…
3 THE DUNGEON ANARCHIST'S COOKBOOK 5 "The third book in the \"Dunge…
4 THE GATE OF THE FERAL GODS 2 "The fourth book in the Dungeo…
As done prior, for the frequency of author appearance on the best-seller list, the above data frame pertaining to Matt Dinniman’s books may also be presented in a cleaner-looking table display.
top_author_books %>%
gt::gt() %>%
gt::tab_header(
title = paste("Books by", top_author, "on the Current List"),
subtitle = "Titles, Weeks on List, Descriptions"
) %>%
gt::cols_label(
title = "Title",
weeks_on_list = "Weeks on List",
description = "Descriptions"
)| Books by Matt Dinniman on the Current List | ||
| Titles, Weeks on List, Descriptions | ||
| Title | Weeks on List | Descriptions |
|---|---|---|
| DUNGEON CRAWLER CARL | 12 | A Coast Guard vet named Carl and his ex-girlfriend’s cat, Princess Donut, are trapped in a fantasy dungeon. |
| CARL'S DOOMSDAY SCENARIO | 10 | The second book in the "Dungeon Crawler Carl" series. Carl and Donut confront an ancient spell and heightened dangers. |
| THE DUNGEON ANARCHIST'S COOKBOOK | 5 | The third book in the "Dungeon Crawler Carl" series. Carl and Donut are up against a subway system filled with monsters. |
| THE GATE OF THE FERAL GODS | 2 | The fourth book in the Dungeon Crawler Carl series. Obstacles abound on the fifth floor of the dungeon. |
From the frequency table and the corresponding plot, it is evident that most authors appear only once on the current Hardcover Fiction best-seller list. However, Matt Dinniman stands out with multiple appearances (four) indicating a notably stronger presence within the list at this point in time. Upon closer examination of his entries, it can be observed that all four books belong to his Dungeon Crawler Carl series. Interestingly, the number of weeks each book has spent on the best-seller list appears to correspond with the order of the books within the series, with the earlier installments remaining on the list for longer durations than the more recent entries. This suggests a pattern of sustained reader engagement with the series over time.
In completing this assignment, the New York Times Books API was successfully accessed through an authenticated request using an environment-stored API key, and the returned JSON response was parsed into a tidy data frame suitable for analysis. From this, it became possible to examine author representation within the current Hardcover Fiction best-seller list and identify a meaningful pattern within the extracted data. Overall, the exercise demonstrated how API-derived JSON data may be securely retrieved, cleaned, and transformed within RStudio for downstream analysis.