output:
  prettydoc::html_pretty:
    theme: architect
    highlight: github

- The Assignment -

Choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it into an R DataFrame

Loading Libraries

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
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.0.5
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(devtools)
## Loading required package: usethis
library(googleAuthR)
## Warning: package 'googleAuthR' was built under R version 4.0.5
library(searchConsoleR)
## Warning: package 'searchConsoleR' was built under R version 4.0.5

Setup for connection to NY Times API

## The following are the calls to the API  - We are testing two (2) calls

## This call is for the most popular articles

response1 = GET("https://api.nytimes.com/svc/mostpopular/v2/emailed/7.json?api-key=ZYSmVxxjIrQ4Hk2wiWUUZCUcaslz3Q8n")

## This call is for the Top Stories currently trending

response2= GET("https://api.nytimes.com/svc/topstories/v2/arts.json?api-key=ZYSmVxxjIrQ4Hk2wiWUUZCUcaslz3Q8n")

## The following checks the status of the call - A response of 200 is normal - 

cat("The status for Most Popular returned is:", response1$status_code)
## The status for Most Popular returned is: 200
cat("The status for Top Stories returned is:", response2$status_code)
## The status for Top Stories returned is: 200
## Converting the JSon data

data1 <- fromJSON(rawToChar(response1$content))

data2 <- fromJSON(rawToChar(response2$content))

names(data1)
## [1] "status"      "copyright"   "num_results" "results"
names(data2)
## [1] "status"       "copyright"    "section"      "last_updated" "num_results" 
## [6] "results"
## Converting to Dataframes

df1 <- data.frame(data1$results, stringsAsFactors = FALSE)

df2 <- data.frame(data2$results, stringsAsFactors = FALSE)

## Adding structure to the dataframes using the Kable package

## Viewing the data

df1 %>% 
  select(title, section, published_date) %>% 
  rename("Title" = title, "Section" = section, "Published Date" = published_date) %>% 
  kable
Title Section Published Date
How Trump Steered Supporters Into Unwitting Donations U.S. 2021-04-03
We Have All Hit a Wall Business 2021-04-03
Kati Kariko Helped Shield the World From the Coronavirus Health 2021-04-08
How to Make Stunning Croissants at Home Food 2021-04-06
A Tiny Particle’s Wobble Could Upend the Known Laws of Physics Science 2021-04-07
A Cyclist on the English Landscape Travel 2021-04-05
What You Need to Know About Your Vaccine Card Travel 2021-04-01
White Evangelical Resistance Is Obstacle in Vaccination Effort U.S. 2021-04-05
Has the Era of Overzealous Cleaning Finally Come to an End? Health 2021-04-08
A New Pasta Shape for Your Pantry Food 2021-04-05
The Unsettling Power of Easter Opinion 2021-04-02
5 Minutes That Will Make You Love Brahms Arts 2021-04-07
Watch These 11 Titles Before They Leave Netflix in April Movies 2021-04-07
Thank God for the Poets Opinion 2021-04-05
Researchers Are Hatching a Low-Cost Coronavirus Vaccine Health 2021-04-05
Fears of White People Losing Out Permeate Capitol Rioters’ Towns, Study Finds U.S. 2021-04-06
Why Is Jesus Still Wounded After His Resurrection? Opinion 2021-04-03
What Georgia’s Voting Law Really Does U.S. 2021-04-02
Curtains Up for the One Percent Style 2021-04-08
Where Boars Hog the Streets World 2021-04-09
df2 %>% 
  select(title, section, published_date) %>% 
  rename("Title" = title, "Section" = section, "Published Date" = published_date) %>% 
  kable
Title Section Published Date
Breonna Taylor Show Points Art Museums to a Faster Track arts 2021-04-11T09:44:09-04:00
A Clash of Wills Keeps a Leonardo Masterpiece Hidden arts 2021-04-11T19:14:26-04:00
‘Nomadland’ Wins Big at Diverse BAFTAs movies 2021-04-11T16:37:20-04:00
‘Younger’ Departs a Covid-Free New York, a Fantasy to the End arts 2021-04-11T09:00:07-04:00
DMX, a Profound Vessel for Pain arts 2021-04-09T12:55:15-04:00
2021 Oscar Nominations: Full Ballot movies 2021-04-09T09:32:50-04:00
Taylor Swift Remade ‘Fearless’ as ‘Taylor’s Version.’ Let’s Discuss. arts 2021-04-09T13:45:04-04:00
Yayoi Kusama’s ‘Cosmic Nature’ Dots a Bronx Garden arts 2021-04-09T14:33:46-04:00
Making Music Visible: Singing in Sign arts 2021-04-09T13:40:31-04:00
Review: Kyle Abraham’s Calm Control of Bodies and Space arts 2021-04-09T13:53:37-04:00
When Boston Ruled the Music World arts 2021-04-09T05:00:23-04:00
3 Artists Are Urged to Go Big. They Didn’t Hold Back. arts 2021-04-09T10:00:14-04:00
Review: Reveling in the Tap Magic of Ayodele Casel arts 2021-04-09T12:08:46-04:00
Keeping Love Close arts 2021-04-08T05:00:03-04:00
Last Call: ‘Shameless’ Showrunner Says Goodbye to the Gallaghers arts 2021-04-11T22:00:06-04:00
The Telling of DMX’s Life Story arts 2021-04-11T17:19:15-04:00
Howard Weitzman, Defense Lawyer for the Famous, Dies at 81 us 2021-04-11T14:06:22-04:00
Benita Raphan, Maker of Lyrical Short Films, Is Dead at 58 arts 2021-04-11T10:43:50-04:00
‘Saturday Night Live’ Reacts to the Derek Chauvin Trial arts 2021-04-11T02:28:37-04:00
Take a Flying Leap, but Bring Your Paper Parachute at-home 2021-04-10T22:39:22-04:00
Chloé Zhao Becomes Second Woman to Win Top Directors Guild Award movies 2021-04-10T22:33:14-04:00
Focus on Wellness and Take a Gardening Class at-home 2021-04-09T22:18:04-04:00
Martina Batan, New York Art Dealer Consumed by a Cold Case, Dies at 62 nyregion 2021-04-09T20:16:37-04:00
James Hampton, Bumbling ‘F Troop’ Bugler, Dies at 84 arts 2021-04-09T18:29:05-04:00
Turkey Fights for Return of a Work It Says Was Looted arts 2021-04-09T18:12:24-04:00
Ethel Gabriel, a Rare Woman in the Record World, Dies at 99 arts 2021-04-09T18:04:25-04:00
Please Stop With the Cheesy Documentary Re-Enactments arts 2021-04-09T17:55:14-04:00
Paul Ritter, British Stage, Film and TV Actor, Dies at 54 theater 2021-04-09T17:42:10-04:00
Peter Manso, Biographer of Brando and Mailer, Dies at 80 books 2021-04-09T17:26:10-04:00
5 Songs to Listen to Right Now arts 2021-04-09T17:10:37-04:00
Writer’s Best Friend books 2021-04-09T15:37:19-04:00
Prince’s Unearthed, Disillusioned Funk, and 10 More New Songs arts 2021-04-09T15:37:16-04:00
‘The Falcon and the Winter Soldier’ Season 1, Episode 4 Recap: Same as the Old Boss? arts 2021-04-09T14:55:59-04:00
How to Resolve a Conflict When You Hate Your Opponent’s Guts books 2021-04-09T13:36:59-04:00
Horse Riders, a City Street and a History Now Captured on Film movies 2021-04-09T13:34:13-04:00
DMX: Hear 10 Essential Songs arts 2021-04-09T13:06:55-04:00
How ‘The Crown’ changed Prince Philip’s image. arts 2021-04-09T12:59:10-04:00
They Hooked Up at Her Bachelorette Party. Now He’s Stalking Her. books 2021-04-09T12:25:02-04:00
DMX, Top-Selling but Troubled Rapper, Dies at 50 arts 2021-04-09T12:21:33-04:00
## Confirming that the datasets are in a dataframe

truefalse <- is.data.frame(df1)
cat("Is df1 a dataframe?", truefalse)
## Is df1 a dataframe? TRUE
truefalse <- is.data.frame(df2)
cat("Is df2 a dataframe?", truefalse)
## Is df2 a dataframe? TRUE