Introduction

I chose to use The New York Times “Most Popular API,” with a focus on the last 30 days (from [insert date]). I have limited experience working with API’s up until this point, so this will serve as a great opportunity to get my feet wet. I will also try to document quagmire’s that come up during this assignment.

Downloading the necessary packages

library(httr)
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

Note: For whatever reason, when I loaded jsonlite and tried to run the code without “jsonlite::” in front of “fromJSON,” the code did not work. I would love to understand why this was the case.

url <- 'https://api.nytimes.com/svc/mostpopular/v2/viewed/30.json?api-key=jBvT5e5Dn4qZTbHgmdS9volt2ddGQIII'

json <- jsonlite::fromJSON(url)
most_pop <- json$results

Printing the head of the data

head(most_pop)
##                                                  uri
## 1 nyt://article/0a905873-70c3-50a8-94cd-ffe76ffd7181
## 2 nyt://article/6119b080-c873-529a-853d-5f1e52729030
## 3 nyt://article/b5a80351-bab7-51d9-8a75-0839caa96540
## 4 nyt://article/2a080dbf-a7b6-5cbf-a6fa-bfdb14530d5c
## 5 nyt://article/52814a70-cf64-5e45-96b8-19eca372b8b0
## 6 nyt://article/7c9a1c63-67a3-57f7-b29d-e033bfa4f862
##                                                                                               url
## 1            https://www.nytimes.com/2023/03/18/us/politics/trump-indictment-arrest-protests.html
## 2                      https://www.nytimes.com/2023/03/10/business/silicon-valley-bank-stock.html
## 3      https://www.nytimes.com/2023/03/20/sports/olympics/jennifer-fox-sexual-abuse-the-tale.html
## 4                      https://www.nytimes.com/2023/03/17/arts/television/lance-reddick-dead.html
## 5                              https://www.nytimes.com/2023/03/12/movies/oscars-winners-list.html
## 6 https://www.nytimes.com/2023/03/18/us/politics/jimmy-carter-october-surprise-iran-hostages.html
##      id asset_id         source published_date             updated  section
## 1 1e+14    1e+14 New York Times     2023-03-18 2023-03-19 13:47:23     U.S.
## 2 1e+14    1e+14 New York Times     2023-03-10 2023-03-14 14:57:20 Business
## 3 1e+14    1e+14 New York Times     2023-03-20 2023-03-21 17:41:42   Sports
## 4 1e+14    1e+14 New York Times     2023-03-17 2023-03-20 11:12:38     Arts
## 5 1e+14    1e+14 New York Times     2023-03-12 2023-03-13 01:10:43   Movies
## 6 1e+14    1e+14 New York Times     2023-03-18 2023-03-19 09:58:59     U.S.
##   subsection nytdsection
## 1   Politics        u.s.
## 2               business
## 3   Olympics      sports
## 4 Television        arts
## 5                 movies
## 6   Politics        u.s.
##                                                                                                                                                                                                                                                                adx_keywords
## 1                                               Presidential Election of 2016;Campaign Finance;Demonstrations, Protests and Riots;United States Politics and Government;Bragg, Alvin;Trump, Donald J;Clifford, Stephanie (1979- );Cohen, Michael D (1966- );Manhattan (NYC)
## 2                                                  Shutdowns (Institutional);Banking and Financial Institutions;Stocks and Bonds;Interest Rates;Start-ups;Regulation and Deregulation of Industry;Silicon Valley Bank;Federal Deposit Insurance Corp;Federal Reserve System
## 3                                                                                        Child Abuse and Neglect;Sex Crimes;Movies;Rowing;Content Type: Personal Profile;internal-sub-only;Coaches and Managers;Dern, Laura;Fox, Jennifer;Nash, Ted;US Center for SafeSport
## 4                                                                                                                                                                                                 Deaths (Obituaries);Actors and Actresses;Television;Movies;Reddick, Lance
## 5                                                                                                                                                                                                                                            Movies;Academy Awards (Oscars)
## 6 Presidential Election of 1980;United States Politics and Government;Kidnapping and Hostages;United States International Relations;Barnes, Ben;Connally, John B Jr.;Casey, William J;Reagan, Ronald Wilson;Carter, Jimmy;Sick, Gary;Democratic Party;Republican Party;Iran
##   column
## 1     NA
## 2     NA
## 3     NA
## 4     NA
## 5     NA
## 6     NA
##                                                                                   byline
## 1 By Maggie Haberman, Jonah E. Bromwich, Ben Protess, Alan Feuer and William K. Rashbaum
## 2                                                      By Emily Flitter and Rob Copeland
## 3                                                                        By Juliet Macur
## 4                                                By Michael Levenson and Neil Genzlinger
## 5                                                                           By Gabe Cohn
## 6                                                                         By Peter Baker
##      type
## 1 Article
## 2 Article
## 3 Article
## 4 Article
## 5 Article
## 6 Article
##                                                                        title
## 1 Trump Claims His Arrest Is Imminent and Calls for Protests, Echoing Jan. 6
## 2                            Silicon Valley Bank Fails After Run on Deposits
## 3         For Years She Said a Coach Abused Her. Now She Has Named a Legend.
## 4              Lance Reddick, Star of ‘The Wire’ and ‘John Wick,’ Dies at 60
## 5                                     Oscars 2023 Winners: The Complete List
## 6   A Four-Decade Secret: One Man’s Story of Sabotaging Carter’s Re-election
##                                                                                                                                                                abstract
## 1                                                                                      His indictment by a Manhattan grand jury is expected, but its timing is unclear.
## 2         The Federal Deposit Insurance Corporation took control of the bank’s assets on Friday. The failure raised concerns that other banks could face problems, too.
## 3 Jennifer Fox has long discussed what happened when she was 13 and her coach was 40. She even based a film on it. Now she has revealed the final detail: his identity.
## 4       A prolific actor, he also starred in the Amazon series “Bosch” and had recently branched out into video games like Horizon Zero Dawn and the Destiny franchise.
## 5                                                                                                                      The list of winners for the 95th Academy Awards.
## 6                                               A prominent Texas politician said he unwittingly took part in a 1980 tour of the Middle East with a clandestine agenda.
##                                                                                                                                             des_facet
## 1                          Presidential Election of 2016, Campaign Finance, Demonstrations, Protests and Riots, United States Politics and Government
## 2 Shutdowns (Institutional), Banking and Financial Institutions, Stocks and Bonds, Interest Rates, Start-ups, Regulation and Deregulation of Industry
## 3                        Child Abuse and Neglect, Sex Crimes, Movies, Rowing, Content Type: Personal Profile, internal-sub-only, Coaches and Managers
## 4                                                                                       Deaths (Obituaries), Actors and Actresses, Television, Movies
## 5                                                                                                                     Movies, Academy Awards (Oscars)
## 6                Presidential Election of 1980, United States Politics and Government, Kidnapping and Hostages, United States International Relations
##                                                                     org_facet
## 1                                                                            
## 2 Silicon Valley Bank, Federal Deposit Insurance Corp, Federal Reserve System
## 3                                                     US Center for SafeSport
## 4                                                                            
## 5                                                                            
## 6                                          Democratic Party, Republican Party
##                                                                                               per_facet
## 1                Bragg, Alvin, Trump, Donald J, Clifford, Stephanie (1979- ), Cohen, Michael D (1966- )
## 2                                                                                                      
## 3                                                                 Dern, Laura, Fox, Jennifer, Nash, Ted
## 4                                                                                        Reddick, Lance
## 5                                                                                                      
## 6 Barnes, Ben, Connally, John B Jr., Casey, William J, Reagan, Ronald Wilson, Carter, Jimmy, Sick, Gary
##         geo_facet
## 1 Manhattan (NYC)
## 2                
## 3                
## 4                
## 5                
## 6            Iran
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     media
## 1                                                                                                                                     image, photo, Former President Donald J. Trump campaigned in Davenport, Iowa, on Monday., Desiree Rios/The New York Times, 1, https://static01.nyt.com/images/2023/03/18/multimedia/18pol-trump-bzvq/18pol-trump-bzvq-thumbStandard.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/18pol-trump-bzvq/18pol-trump-bzvq-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/18pol-trump-bzvq/18pol-trump-bzvq-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 2                                                                                     image, photo, Silicon Valley Bank’s headquarters in Santa Clara, Calif., on Friday. Founded in 1983, Silicon Valley Bank was a big lender to tech start-ups., Jim Wilson/The New York Times, 1, https://static01.nyt.com/images/2023/03/10/multimedia/10SV-Bank-sub/10SV-Bank-sub-thumbStandard.jpg, https://static01.nyt.com/images/2023/03/10/multimedia/10SV-Bank-sub/10SV-Bank-sub-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/03/10/multimedia/10SV-Bank-sub/10SV-Bank-sub-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 3                                                                                                                     image, photo, Jennifer Fox made the film “The Tale” about the summer she was 13., Ingmar Nolting for The New York Times, 1, https://static01.nyt.com/images/2023/03/10/multimedia/00rowing-abuse-qljp/00rowing-abuse-qljp-thumbStandard.jpg, https://static01.nyt.com/images/2023/03/10/multimedia/00rowing-abuse-qljp/00rowing-abuse-qljp-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/03/10/multimedia/00rowing-abuse-qljp/00rowing-abuse-qljp-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 4                                                                                                                                       image, photo, Mr. Reddick in an episode of “The Wire.”, Paul Schiraldi/HBO, 0, https://static01.nyt.com/images/2023/03/18/multimedia/17xp-reddick-02-fjhk-print2/17xp-reddick-02-fjhk-thumbStandard.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/17xp-reddick-02-fjhk-print2/17xp-reddick-02-fjhk-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/17xp-reddick-02-fjhk-print2/17xp-reddick-02-fjhk-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 5                     image, photo, Ke Huy Quan accepting the Oscar for best supporting actor for his performance in “Everything Everywhere All at Once.”, Todd Heisler/The New York Times, 1, https://static01.nyt.com/images/2023/03/12/multimedia/12oscars-list-ke-swap-jcfb/12oscars-list-ke-swap-jcfb-thumbStandard-v2.jpg, https://static01.nyt.com/images/2023/03/12/multimedia/12oscars-list-ke-swap-jcfb/12oscars-list-ke-swap-jcfb-mediumThreeByTwo210-v2.jpg, https://static01.nyt.com/images/2023/03/12/multimedia/12oscars-list-ke-swap-jcfb/12oscars-list-ke-swap-jcfb-mediumThreeByTwo440-v2.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 6 image, photo, “History needs to know that this happened,” Ben Barnes now says of his trip to the Middle East in 1980., Christopher Lee for The New York Times, 1, https://static01.nyt.com/images/2023/03/18/multimedia/18dc-carter-hostage-barnes-pjkb/18dc-carter-hostage-barnes-pjkb-thumbStandard.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/18dc-carter-hostage-barnes-pjkb/18dc-carter-hostage-barnes-pjkb-mediumThreeByTwo210-v3.jpg, https://static01.nyt.com/images/2023/03/18/multimedia/18dc-carter-hostage-barnes-pjkb/18dc-carter-hostage-barnes-pjkb-mediumThreeByTwo440-v3.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
##   eta_id
## 1      0
## 2      0
## 3      0
## 4      0
## 5      0
## 6      0

Note: What would have been cool is if the data included a view count, but it does not seem like that is the case.

most_pop_sections <- most_pop %>%
  select('section') %>%
  group_by(section) %>%
  summarize(percent = 100 * n()/nrow(.)) %>%
  arrange(desc(percent))

knitr::kable(most_pop_sections)
section percent
U.S. 35
Business 10
Movies 10
New York 10
World 10
Arts 5
Opinion 5
Science 5
Sports 5
Well 5

Conclusion

Within the twenty most popular articles in the past 30 days, it seems that by far and away the most popular article section is the “U.S.” section. Now this analysis only pertains to the last 30 days and so this popularity may change, but I would guess that with increasingly polarized politics, this section viewership may not change all that much.