Load the desired libraries.

library(httr)
library(jsonlite)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()  masks stats::filter()
## ✖ purrr::flatten() masks jsonlite::flatten()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

A response code of 200 means “OK” and it indicates that the request has succeeded.

Articles_untidy <- response$content %>%
  rawToChar() %>%
  fromJSON(flatten = TRUE) %>%
  as.data.frame()
head(Articles_untidy)
##   status                                                            copyright
## 1     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
## 2     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
## 3     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
## 4     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
## 5     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
## 6     OK Copyright (c) 2024 The New York Times Company.  All Rights Reserved.
##   num_results                                            results.uri
## 1          20     nyt://article/69b6695e-4442-5fe6-bfca-1fd1763c67d1
## 2          20     nyt://article/69db6276-a930-5be8-a19b-ab5589bf18ee
## 3          20     nyt://article/e46f6bab-7a8a-5f25-87ea-c673c7d1f896
## 4          20     nyt://article/0670b049-30f8-5973-bb41-83bd8735e158
## 5          20 nyt://interactive/ea933bb6-5b88-56c0-a956-2d20792cbf1d
## 6          20     nyt://article/a4d0cb8b-9f32-5ff7-8071-6ebbe282c673
##                                                                            results.url
## 1           https://www.nytimes.com/2024/03/21/health/pig-kidney-organ-transplant.html
## 2           https://www.nytimes.com/2024/03/12/books/review/devout-anna-gazmarian.html
## 3         https://www.nytimes.com/2024/03/18/nyregion/trump-bond-civil-fraud-case.html
## 4     https://www.nytimes.com/2024/03/18/style/kristen-stewart-love-lies-bleeding.html
## 5                 https://www.nytimes.com/interactive/2024/03/15/upshot/flashback.html
## 6 https://www.nytimes.com/2024/03/21/world/americas/mexico-timeshare-fraud-cartel.html
##   results.id results.asset_id results.source results.published_date
## 1      1e+14            1e+14 New York Times             2024-03-21
## 2      1e+14            1e+14 New York Times             2024-03-12
## 3      1e+14            1e+14 New York Times             2024-03-18
## 4      1e+14            1e+14 New York Times             2024-03-18
## 5      1e+14            1e+14 New York Times             2024-03-15
## 6      1e+14            1e+14 New York Times             2024-03-21
##       results.updated results.section results.subsection results.nytdsection
## 1 2024-03-22 08:21:54          Health                                 health
## 2 2024-03-12 16:34:36           Books        Book Review               books
## 3 2024-03-19 08:52:30        New York                               new york
## 4 2024-03-20 22:58:47           Style                                  style
## 5 2024-03-22 18:05:06      The Upshot                             the upshot
## 6 2024-03-22 09:44:02           World           Americas               world
##                                                                                                                                                                         results.adx_keywords
## 1                                          Transplants;Kidneys;Pigs;Genetic Engineering;Surgery and Surgeons;Diabetes;Black People;your-feed-science;Massachusetts General Hospital;eGenesis
## 2                                                                Books and Literature;Christians and Christianity;Mental Health and Disorders;Content Type: Personal Profile;Gazmarian, Anna
## 3                                                                             New York State Civil Case Against Trump (452564/2022);Insurance;Credit and Debt;Trump, Donald J;New York State
## 4                                                                         Fashion and Apparel;Women and Girls;Lingerie and Underwear;Actors and Actresses;your-feed-fashion;Stewart, Kristen
## 5                                                                                                                                                 internal-paywall-exempt;Content Type: Quiz
## 6 Real Estate and Housing (Residential);Drug Cartels;Frauds and Swindling;Time-Sharing;Elderly;Jalisco New Generation Cartel;Federal Bureau of Investigation;Mexico;Puerto Vallarta (Mexico)
##   results.column                                      results.byline
## 1             NA                                 By Roni Caryn Rabin
## 2             NA                                    By Carlene Bauer
## 3             NA By Ben Protess, Maggie Haberman and Kate Christobek
## 4             NA                                 By Vanessa Friedman
## 5             NA                                                    
## 6             NA                                  By Maria Abi-Habib
##   results.type
## 1      Article
## 2      Article
## 3      Article
## 4      Article
## 5  Interactive
## 6      Article
##                                                             results.title
## 1      Surgeons Transplant Pig Kidney Into a Patient, a Medical Milestone
## 2                      She Trusted God and Science. They Both Failed Her.
## 3 Trump Spurned by 30 Companies as He Seeks Bond in $454 Million Judgment
## 4                     Kristen Stewart Uses Naked Dressing to Make a Point
## 5                     Flashback: Your Weekly History Quiz, March 16, 2024
## 6        A Mexican Drug Cartel’s New Target? Seniors and Their Timeshares
##                                                                                                                                                                        results.abstract
## 1                                                               The man continues to improve, doctors said. Organs from genetically engineered pigs one day may make dialysis obsolete.
## 2                    In “Devout,” an author who grew up in the evangelical church recounts her struggle to find spiritual and psychological well-being after a mental health challenge.
## 3              Donald J. Trump’s lawyers said in a court filing that he faces “insurmountable difficulties” as he tries to raise cash for the civil fraud penalty he faces in New York.
## 4                                                                                                                         Her press tour for “Love Lies Bleeding” was something to see.
## 5                                                                                                                                                     Can you sort 8 historical events?
## 6 One of Mexico’s most violent criminal groups, Jalisco New Generation, runs call centers that offer to buy retirees’ vacation properties. Then, it empties its victims’ bank accounts.
##                                                                                                  results.des_facet
## 1 Transplants, Kidneys, Pigs, Genetic Engineering, Surgery and Surgeons, Diabetes, Black People, your-feed-science
## 2   Books and Literature, Christians and Christianity, Mental Health and Disorders, Content Type: Personal Profile
## 3                                New York State Civil Case Against Trump (452564/2022), Insurance, Credit and Debt
## 4            Fashion and Apparel, Women and Girls, Lingerie and Underwear, Actors and Actresses, your-feed-fashion
## 5                                                                      internal-paywall-exempt, Content Type: Quiz
## 6                 Real Estate and Housing (Residential), Drug Cartels, Frauds and Swindling, Time-Sharing, Elderly
##                                                results.org_facet
## 1                       Massachusetts General Hospital, eGenesis
## 2                                                               
## 3                                                               
## 4                                                               
## 5                                                               
## 6 Jalisco New Generation Cartel, Federal Bureau of Investigation
##   results.per_facet                results.geo_facet
## 1                                                   
## 2   Gazmarian, Anna                                 
## 3   Trump, Donald J                   New York State
## 4  Stewart, Kristen                                 
## 5                                                   
## 6                   Mexico, Puerto Vallarta (Mexico)
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          results.media
## 1                      image, photo, Surgeons performed the world’s first genetically modified pig kidney transplant into a living human at Massachusetts General Hospital on March 16., Michelle Rose/Massachusetts General Hospital, via Agence France-Presse — Getty Images, 1, https://static01.nyt.com/images/2024/03/21/multimedia/21transplant-sub-clzp/21transplant-sub-clzp-thumbStandard.jpg, https://static01.nyt.com/images/2024/03/21/multimedia/21transplant-sub-clzp/21transplant-sub-clzp-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2024/03/21/multimedia/21transplant-sub-clzp/21transplant-sub-clzp-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 2               image, photo, Anna Gazmarian did everything that millennial evangelicals were supposed to do: She wore a purity ring, listened to sanctioned bands and avoided Harry Potter. And yet, she believed, her faith was inadequate., Jo Lindsay Co, 0, https://static01.nyt.com/images/2024/02/12/books/review/12anna-gazmarian-author/12anna-gazmarian-author-thumbStandard.jpg, https://static01.nyt.com/images/2024/02/12/books/review/12anna-gazmarian-author/12anna-gazmarian-author-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2024/02/12/books/review/12anna-gazmarian-author/12anna-gazmarian-author-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 3                                                                                                  image, photo, Donald J. Trump’s filing one week before the bond is due raised the prospect that the former president might now face a financial crisis., Maansi Srivastava/The New York Times, 1, https://static01.nyt.com/images/2024/03/18/multimedia/18trump-bond-pwgz/18trump-bond-pwgz-thumbStandard.jpg, https://static01.nyt.com/images/2024/03/18/multimedia/18trump-bond-pwgz/18trump-bond-pwgz-mediumThreeByTwo210-v3.jpg, https://static01.nyt.com/images/2024/03/18/multimedia/18trump-bond-pwgz/18trump-bond-pwgz-mediumThreeByTwo440-v3.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 4                                                                                                                      image, photo, Kristen Stewart, pantsless at the Los Angeles premiere of “Love Lies Bleeding.”, Emma Mcintyre/Getty Images, 1, https://static01.nyt.com/images/2024/03/15/multimedia/KRISTEN-STWEART-jbct-promo/KRISTEN-STWEART-jbct-promo-thumbStandard.jpg, https://static01.nyt.com/images/2024/03/15/multimedia/KRISTEN-STWEART-jbct-promo/KRISTEN-STWEART-jbct-promo-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2024/03/15/multimedia/KRISTEN-STWEART-jbct-promo/KRISTEN-STWEART-jbct-promo-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 5                                                                                                                                                                                                                                                                                                                  image, , , , 1, https://static01.nyt.com/images/2024/03/15/upshot/flashback-promo/flashback-promo-thumbStandard.jpg, https://static01.nyt.com/images/2024/03/15/upshot/flashback-promo/flashback-promo-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2024/03/15/upshot/flashback-promo/flashback-promo-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
## 6 image, photo, Tourists in Puerto Vallarta, a popular beach town in Mexico, in February. Over the last five years, American timeshare owners were bilked out of $288 million, according to the F.B.I., Alejandro Cegarra for The New York Times, 1, https://static01.nyt.com/images/2024/03/18/multimedia/00mexico-timeshare-01-gkfw/00mexico-timeshare-01-gkfw-thumbStandard.jpg, https://static01.nyt.com/images/2024/03/18/multimedia/00mexico-timeshare-01-gkfw/00mexico-timeshare-01-gkfw-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2024/03/18/multimedia/00mexico-timeshare-01-gkfw/00mexico-timeshare-01-gkfw-mediumThreeByTwo440.jpg, Standard Thumbnail, mediumThreeByTwo210, mediumThreeByTwo440, 75, 140, 293, 75, 210, 440
##   results.eta_id
## 1              0
## 2              0
## 3              0
## 4              0
## 5              0
## 6              0

The code above fetches data from the server, converts it from raw format to character format, parses it as JSON data and converts it into a data frame.

Articles_tidy <- Articles_untidy %>% 
  select(
    "Published Date" = results.published_date,
    "Popular Articles" = results.title,
    "Section" = results.section,
    "Abstract" = results.abstract
  )
View(Articles_tidy)

The code above takes the Articles_untidy dataset, selects specific columns and renames them.