For this assignment, I’ll be referencing the New York Times Books API, which returns information for their Best Sellers list. I’ll start by looking for a particular science writer, Carl Sagan.
library(devtools)
## Warning: package 'devtools' was built under R version 3.6.3
## Loading required package: usethis
library(jsonlite)
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
nyt_books_df <- fromJSON("https://api.nytimes.com/svc/books/v3/reviews.json?author=Carl+Sagan&api-key=FPnmDxNHarXfeDsWWYnSqrrGXOjEI1AK", flatten = TRUE) %>% data.frame()
names(nyt_books_df)
## [1] "status" "copyright" "num_results"
## [4] "results.url" "results.publication_dt" "results.byline"
## [7] "results.book_title" "results.book_author" "results.summary"
## [10] "results.uuid" "results.uri" "results.isbn13"
head(nyt_books_df)
## status copyright
## 1 OK Copyright (c) 2020 The New York Times Company. All Rights Reserved.
## 2 OK Copyright (c) 2020 The New York Times Company. All Rights Reserved.
## 3 OK Copyright (c) 2020 The New York Times Company. All Rights Reserved.
## 4 OK Copyright (c) 2020 The New York Times Company. All Rights Reserved.
## 5 OK Copyright (c) 2020 The New York Times Company. All Rights Reserved.
## num_results
## 1 5
## 2 5
## 3 5
## 4 5
## 5 5
## results.url
## 1 http://www.nytimes.com/1985/11/03/books/theology-and-the-interstellar-subway.html
## 2 http://www.nytimes.com/1985/12/29/books/in-short-nonfiction-237842.html
## 3 http://www.nytimes.com/1996/04/07/books/invasion-of-the-body-snatchers.html
## 4 http://www.nytimes.com/1991/01/06/books/chilly-scenes-of-nuclear-winter.html
## 5 http://www.nytimes.com/1981/01/25/books/ten-million-civilizations-nearby.html
## results.publication_dt results.byline
## 1 1985-11-03 GREGORY BENFORD
## 2 1985-12-29 NICHOLAS A. BASBANESN
## 3 1996-04-07 JAMES GORMAN
## 4 1991-01-06 LEN ACKLAND
## 5 1981-01-25 JAMES MICHENER
## results.book_title
## 1 Contact
## 2 Comet
## 3 Demon-Haunted World : Science as a Candle in the Dark
## 4 Path Where No Man Thought : Nuclear Winter and the End of the Arms Race
## 5 Cosmos
## results.book_author results.summary results.uuid
## 1 Carl Sagan 00000000-0000-0000-0000-000000000000
## 2 Carl Sagan 00000000-0000-0000-0000-000000000000
## 3 Carl Sagan 00000000-0000-0000-0000-000000000000
## 4 Carl Sagan 00000000-0000-0000-0000-000000000000
## 5 Carl Sagan 00000000-0000-0000-0000-000000000000
## results.uri results.isbn13
## 1 nyt://book/00000000-0000-0000-0000-000000000000 9781442006614
## 2 nyt://book/00000000-0000-0000-0000-000000000000 9780517685068
## 3 nyt://book/00000000-0000-0000-0000-000000000000 9780345409461
## 4 nyt://book/00000000-0000-0000-0000-000000000000 9780679727965
## 5 nyt://book/00000000-0000-0000-0000-000000000000 9780394502946
Next, I’ll take a look at when Dr. Sagan’s books were published.
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
nyt_books_df <- nyt_books_df %>%
arrange(results.publication_dt)
nyt_books_df$results.publication_dt <- as.Date(nyt_books_df$results.publication_dt)
time_length(nyt_books_df$results.publication_dt[5] - nyt_books_df$results.publication_dt[1], "years")
## [1] 15.20822
It looks like his best sellers span 1981 to 1996, indicating that his book notoriety continued over 15 years up until his year of his death in 1996.