Load relevant Libraries
library(knitr)
## Warning: package 'knitr' was built under R version 3.4.3
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
library(stringr)
library(jsonlite)
library(httr)
library(pander)
Used the API key given by NY Times to retrieve opinion articles
apiKey <- "&api-key=ab76a2fdad8a41cabb293ebb7807d46d"
url <-"https://api.nytimes.com/svc/mostpopular/v2/mostshared/Opinion/30.json?"
nyt <- paste(url, apiKey, sep = "")
Utilized GET to retrieve json object from NY Times API
nytData <- GET(nyt)
content(nytData, 'text')
Converted into an R data frame
json_raw <- content(nytData, type = "text", encoding = "UTF-8")
json1 <- fromJSON(json_raw)
df <- as.data.frame(json1$results)
df1 <- df %>% select(byline, title, abstract, published_date)
df1$byline <- str_replace(df1$byline, 'By ', "")
df1 %>% kable("html")
byline | title | abstract | published_date |
---|---|---|---|
JOHN PAUL STEVENS | John Paul Stevens: Repeal the Second Amendment | This weekend’s marches make it clear: To enact real gun control, we need to change the Constitution. | 2018-03-27 |
ISABELLE ROBINSON | I Tried to Befriend Nikolas Cruz. He Still Killed My Friends. | The notion that the Parkland shootings wouldn’t have occurred if students had been kinder is deeply dangerous. | 2018-03-27 |
MARGARET RENKL | The Pain of Loving Old Dogs | It’s hard to know what to do when age brings a faithful companion so much fear and suffering. | 2018-02-25 |
TIM KREIDER | Go Ahead, Millennials, Destroy Us | Whenever you disapprove of young people, you’re in the wrong, because you’re going to die and they’ll get to write history. | 2018-03-02 |
DAVID BROOKS | Good Leaders Make Good Schools | Principals are the key to success. | 2018-03-12 |
THOMAS L. FRIEDMAN | What Trump and Putin Have in Common | They are steadily eroding norms, but they can be stopped. | 2018-03-20 |
DAVID LEONHARDT | Big Sugar Versus Your Body | The sugar industry has spent years trying to fool you into eating poorly. Fortunately, you have the ability to fight back. | 2018-03-11 |
TIMOTHY EGAN | How the Irish Could Still Save Civilization | Ireland’s leader, Leo Varadkar, the gay son of a Hindu father of Indian descent, tries to nudge the United States back to the moral high ground. | 2018-03-16 |
ZEYNEP TUFEKCI | YouTube, the Great Radicalizer | The videos it recommends seem to get more and more extreme. | 2018-03-10 |
TIM WU | The Tyranny of Convenience | All the personal tasks in our lives are being made easier. But at what cost? | 2018-02-16 |
MICHAEL IAN BLACK | The Boys Are Not All Right | What do America’s mass shootings have in common? Guns, yes. But also, boys. | 2018-02-21 |
DAVID REICH | How Genetics Is Changing Our Understanding of ‘Race’ | If scientists avoid discussing the topic candidly, racist theories will fill the vacuum. | 2018-03-23 |
ZEYNEP TUFEKCI | Facebook’s Surveillance Machine | It’s true that the Cambridge Analytica incident wasn’t a security breach. It was something far worse. | 2018-03-19 |
SINAN ANTOON | Fifteen Years Ago, America Destroyed My Country | Let’s stop calling the invasion of Iraq a “blunder” and call it what it is: a crime. | 2018-03-19 |
THE EDITORIAL BOARD | Having a Torturer Lead the C.I.A. | Few American officials were so directly involved in the frenzy of abuse after 9/11 as Gina Haspel, President Trump’s choice to head the agency. | 2018-03-13 |
NICHOLAS KRISTOF | I Saw a Genocide in Slow Motion | Myanmar continues to kill its Rohingya, now by denying them health care and sometimes food instead of by wielding machetes and firing bullets. | 2018-03-02 |
BARI WEISS | We’re All Fascists Now | Why are feminists and liberals getting thrown into the slop bucket with the likes of Richard Spencer? | 2018-03-07 |
KARLA CORNEJO VILLAVICENCIO | The Americans Left Behind by Deportation | The aggressive detention and removal of undocumented immigrants is having a devastating impact on their American children and spouses. | 2018-02-28 |
PAUL KRUGMAN | Taxpayers, You’ve Been Scammed | The tax cuts may look like a gift, but the middle class will end up paying the bill. | 2018-03-01 |
PAGAN KENNEDY | The Secret to a Longer Life? Don’t Ask These Dead Longevity Researchers | Some of the biggest names in dieting, organic agriculture and preventive medicine died at surprisingly young ages. | 2018-03-09 |