I will start by studying the code examples in the link to learn how to call APIs in R. Then, I will follow the assignment instructions to retrieve, clean, and analyze the data. Finally, I will organize the results as required for the assignment.
Question: What are the top five books on The New York Times fiction bestseller list?
2.What data challenges do I anticipate?
As I learn and code, there will be some parts where I don’t quite understand the details, and I may need more time to grasp them.
3. Store key in an environment variable
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.1 ✔ stringr 1.5.2
✔ ggplot2 4.0.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# A tibble: 15 × 5
title author publisher rank weeks_on_list
<chr> <chr> <chr> <int> <int>
1 JUDGE STONE Viola Davis a… Little, … 1 2
2 THE CORRESPONDENT Virginia Evans Crown 2 21
3 BLOODLUST Sandra Brown Grand Ce… 3 1
4 MY HUSBAND'S WIFE Alice Feeney Pine & C… 4 8
5 INNAMORATA Ava Reid Del Rey 5 1
6 CARL'S DOOMSDAY SCENARIO Matt Dinniman Ace 6 10
7 MOTHER OF DEATH AND DAWN Carissa Broad… Bramble 7 1
8 KIN Tayari Jones Knopf 8 4
9 BETWEEN TWO FIRES Christopher B… Tor Nigh… 9 3
10 THE DUNGEON ANARCHIST'S COOKBOOK Matt Dinniman Ace 10 5
11 THE WIDOW John Grisham Doubleday 11 22
12 ALCHEMISED SenLinYu Del Rey 12 26
13 THE CROSSROADS C.J. Box Putnam 13 4
14 THE GATE OF THE FERAL GODS Matt Dinniman Ace 14 2
15 DUNGEON CRAWLER CARL Matt Dinniman Ace 15 12
# A tibble: 15 × 4
title author rank weeks_on_list
<chr> <chr> <int> <int>
1 ALCHEMISED SenLinYu 12 26
2 THE WIDOW John Grisham 11 22
3 THE CORRESPONDENT Virginia Evans 2 21
4 DUNGEON CRAWLER CARL Matt Dinniman 15 12
5 CARL'S DOOMSDAY SCENARIO Matt Dinniman 6 10
6 MY HUSBAND'S WIFE Alice Feeney 4 8
7 THE DUNGEON ANARCHIST'S COOKBOOK Matt Dinniman 10 5
8 KIN Tayari Jones 8 4
9 THE CROSSROADS C.J. Box 13 4
10 BETWEEN TWO FIRES Christopher Buehlman 9 3
11 JUDGE STONE Viola Davis and James P… 1 2
12 THE GATE OF THE FERAL GODS Matt Dinniman 14 2
13 BLOODLUST Sandra Brown 3 1
14 INNAMORATA Ava Reid 5 1
15 MOTHER OF DEATH AND DAWN Carissa Broadbent 7 1
(1)The five books with the longest cumulative time on the chart.
The current Fiction chart, sorted by “weeks_on_list” from highest to lowest, is as follows: “ALCHEMISED,” “THE WIDOW,” “THE CORRESPONDENT,” “DUNGEON CRAWLER CARL,” and “CARL’S DOOMSDAY SCENARIO.” These five books are the fiction on the current chart that have been on the list the longest and have maintained the most stable rankings.
# A tibble: 15 × 4
title author rank weeks_on_list
<chr> <chr> <int> <int>
1 JUDGE STONE Viola Davis and James P… 1 2
2 THE CORRESPONDENT Virginia Evans 2 21
3 BLOODLUST Sandra Brown 3 1
4 MY HUSBAND'S WIFE Alice Feeney 4 8
5 INNAMORATA Ava Reid 5 1
6 CARL'S DOOMSDAY SCENARIO Matt Dinniman 6 10
7 MOTHER OF DEATH AND DAWN Carissa Broadbent 7 1
8 KIN Tayari Jones 8 4
9 BETWEEN TWO FIRES Christopher Buehlman 9 3
10 THE DUNGEON ANARCHIST'S COOKBOOK Matt Dinniman 10 5
11 THE WIDOW John Grisham 11 22
12 ALCHEMISED SenLinYu 12 26
13 THE CROSSROADS C.J. Box 13 4
14 THE GATE OF THE FERAL GODS Matt Dinniman 14 2
15 DUNGEON CRAWLER CARL Matt Dinniman 15 12
(2)The top five books on the current
The current Fiction chart, sorted by rank, lists the top five as follows: ‘JUDGE STONE’, ‘THE CORRESPONDENT’, ‘BLOODLUST’, ‘MY HUSBAND’S WIFE’, and ‘INNAMORATA’. These are the five most popular fiction on the list.
“THE CORRESPONDENT” ranks second, having appeared on the list 21 times—just five fewer than the top one by ‘weeks_on_list’. Overall, this is the most popular fiction.
Additional information
1. I chose the New York Times Books API, specifically the endpoint “https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json”. This endpoint is used to retrieve the New York Times’ current Hardcover Fiction bestseller list. Retrieving the New York Times bestseller list and related book information (top five) in R.
2. I sent a request to the endpoint “/svc/books/v3/lists/current/hardcover-fiction.json” to retrieve the data for the current Hardcover Fiction list, and used the ‘api-key’ parameter in the request to authenticate.
3. I extracted data from ‘json\(results\)books’ in the return results and organized it into a tidy data frame. I retained the ‘title’, ‘author’, ‘publisher’, ‘rank’, and `weeks_on_list’ columns. There are no missing values in the data.