Libraries used

knitr::opts_chunk$set(echo = TRUE)
library(httr)
library(knitr)
library(kableExtra)

For this assignment, I used the “Times Newswire API”

This API is set up to hold an up to the minute stream of the latest articles published by the New York Times. This stream holds 20 of the latest articles.

# save the url with api-key
url <- "https://api.nytimes.com/svc/news/v3/content/all/all.json?api-key=SoV2EDJdCsYfjVcQeelgFOdkaAlJtPts"

Using the httr library to get the json data from the API

nyt <- GET(url)

Parsing the json data, and saving certain parts in vectors

details <- content(nyt, "parse")

# creating empty vectors to store results in the following for loop
titles = vector()
abstracts = vector()
sections = vector()
pb_date = vector()
urls = vector()

# iterating through the parsed results and storing data from various sections in vectors to be used later to combine into the final dataframe
for(i in 1:length(details$results)){
  titles[i] <- details$results[[i]]$title
  abstracts[i] <- details$results[[i]]$abstract
  sections[i] <- details$results[[i]]$section
  pb_date[i] <- details$results[[i]]$published_date
  urls[i] <- details$results[[i]]$url
}

Saving to a final data frame

# adding all of the vectors to a final dataframe
final_df <- data.frame(titles, abstracts, sections, pb_date, urls)

# printing the final dataframe
kable(final_df, align = rep('c', 5)) %>% 
  kable_styling(bootstrap_options = c("striped"), full_width = F)
titles abstracts sections pb_date urls
Why Did Republicans Storm the Capitol? They’re Running Out of Options As more testimony is disclosed, it becomes clearer that President Trump’s only defense against impeachment is to distract from the facts. Opinion 2019-10-23T20:14:15-04:00 https://www.nytimes.com/2019/10/23/opinion/impeachment-hearing-republicans.html
The Trump Impeachment Inquiry: What Happened Today After a number of days dominated by the findings of the Democratic-led investigation, Wednesday brought an unconventional Republican response. U.S. 2019-10-23T20:14:13-04:00 https://www.nytimes.com/2019/10/23/us/politics/trump-impeachment-what-happened.html
Colorado Report Accuses 43 Catholic Priests of Child Sex Abuse Investigators said 166 children were abused since 1950, but victims’ groups said the number could be higher. They criticized the inquiry as overly reliant on the voluntary participation of the Catholic Church. U.S. 2019-10-23T19:27:30-04:00 https://www.nytimes.com/2019/10/23/us/politics/colorado-catholic-church-abuse-investigation.html
All-Female Panel Will Moderate Next Democratic Debate in Georgia Rachel Maddow, Andrea Mitchell, Ashley Parker and Kristen Welker will moderate the debate. NBC News is preparing for the event as it faces scrutiny for recent controversies. Business 2019-10-23T19:17:02-04:00 https://www.nytimes.com/2019/10/23/business/media/democratic-debate-female-moderators.html
Why the New Emmett Till Memorial Needed to Be Bulletproof Vandals destroyed numerous signs remembering the 1955 lynching, mirroring the violence inflicted on the teenager himself. Opinion 2019-10-23T19:00:09-04:00 https://www.nytimes.com/2019/10/23/opinion/emmett-till-memorial.html
Rose McGowan Sues Harvey Weinstein and Lawyers He Enlisted to Discredit Her The lawsuit says David Boies and Lisa Bloom used underhanded tactics to stop the actress from publicizing her sexual assault allegations against the producer. Arts 2019-10-23T18:56:51-04:00 https://www.nytimes.com/2019/10/23/arts/rose-mcgowan-harvey-weinstein-lawsuit.html
¿Cuánto cuesta desalinizar el agua que necesita el mundo? La desalinización del agua del mar parece una solución a la creciente escasez de agua dulce, pero los costos financieros y energéticos limitan su potencial. en Español 2019-10-23T18:55:40-04:00 https://www.nytimes.com/es/2019/10/23/espanol/mundo/agua-desalinizada.html
Lebanon Protests Unite Sects in Demanding New Government Lebanon’s protests, the largest since its independence, have moved from fury over the economy and corruption to demands for a new political system. World 2019-10-23T18:55:13-04:00 https://www.nytimes.com/2019/10/23/world/middleeast/lebanon-protests.html
Trump’s War on the ‘Deep State’ Turns Against Him The impeachment inquiry is in some ways the culmination of a battle between the president and the government institutions he distrusted and disparaged. U.S. 2019-10-23T18:42:04-04:00 https://www.nytimes.com/2019/10/23/us/politics/trump-deep-state-impeachment.html
Behind Closed Doors Republicans stormed a secure room in the Capitol — and signaled a new strategy on impeachment. U.S. 2019-10-23T18:31:21-04:00 https://www.nytimes.com/2019/10/23/us/politics/on-politics-impeachment-scif.html
Pick Trump’s Worst Cabinet Member Vote for the absolute bottom. Opinion 2019-10-23T18:30:06-04:00 https://www.nytimes.com/2019/10/23/opinion/trump-cabinet.html
Carlos Vela Just Wants to Go to Work Does the Los Angeles F.C. star take soccer seriously enough? His critics, his former teams and even some of his rivals aren’t sure. Vela says he will win, or lose, on his terms. Sports 2019-10-23T18:00:10-04:00 https://www.nytimes.com/2019/10/23/sports/carlos-vela-lafc-mls.html
Two Strains of Polio Are Gone, but the End of the Disease Is Still Far Off Only polio virus Type 1 persists, and only in Pakistan and Afghanistan. But now mutant vaccine viruses are paralyzing some unvaccinated children. Health 2019-10-23T18:00:10-04:00 https://www.nytimes.com/2019/10/23/health/polio-strain-eradication.html
Syria, Google, California: Your Wednesday Evening Briefing Here’s what you need to know at the end of the day. Briefing 2019-10-23T17:59:35-04:00 https://www.nytimes.com/2019/10/23/briefing/syria-google-california.html
Getting Brexit Deal Over Finish Line Would Only Begin a Tortuous New Race Britain would have no more than a few months to negotiate a new trade agreement with Brussels, a process that typically takes years. World 2019-10-23T17:37:35-04:00 https://www.nytimes.com/2019/10/23/world/brexit-boris-johnson.html
Mandla Morris, Son of Stevie Wonder, Pursues Music and Fashion The 14-year-old appeared in “A Star Is Born” and “Dancing With the Stars: Juniors.” Style 2019-10-23T17:30:02-04:00 https://www.nytimes.com/2019/10/23/style/mandla-morris-stevie-wonder-son.html
One Thing You Can Do: Look for the Energy Star Label Also this week, Exxon Mobil goes to court. Climate 2019-10-23T17:22:46-04:00 https://www.nytimes.com/2019/10/23/climate/nyt-cilmate-newsletter-energy-star.html
Tesla Reports Profit for Quarter, Sending Shares Soaring The electric-car maker’s revenue declined, but it said it had removed “substantial cost” from its operations. Business 2019-10-23T17:21:27-04:00 https://www.nytimes.com/2019/10/23/business/tesla-earnings.html
¿Por qué persisten los mitos sobre las gaseosas de dieta? La existencia de tantos estudios (muchas veces contradictorios) sobre los efectos de los refrescos dietéticos en la salud explica un grave problema de la investigación alimentaria. en Español 2019-10-23T17:19:48-04:00 https://www.nytimes.com/es/2019/10/23/espanol/mitos-refresco-dieta.html
Hildegard Bachert, 98, Dies; Championed Klimt, Schiele and Grandma Moses In her 78 years at the Galerie St. Etienne in Manhattan, she promoted German and Austrian Expressionists as well as the celebrated American folk artist. Arts 2019-10-23T17:11:15-04:00 https://www.nytimes.com/2019/10/23/arts/hildegard-bachert-dead.html

Similar work in python

I also decided to build this out in Python as well, to gain a little more experience working with the Pandas library and python code. If interested, you can find my code at this Jupyter Notebook file on my GitHub repository as the .ipynb file.

An html version of this file is also at the same location as above.