library(httr)
library(jsonlite)
library(dplyr)
library(tidyr)
library(stringr)
# Set a URL with API key.
URL <- "https://api.nytimes.com/svc/movies/v2/reviews/all.json?api-key=FkAGivNSg3efOG9ZUOK4EoIc2ZJE137C"
# Using GET method to get movies reviews dataset.
nytimes.movies <- GET(URL)
# Checking response from New Times API.
nytimes.movies
## Response [https://api.nytimes.com/svc/movies/v2/reviews/all.json?api-key=FkAGivNSg3efOG9ZUOK4EoIc2ZJE137C]
## Date: 2019-10-27 21:29
## Status: 200
## Content-Type: application/json; charset=UTF-8
## Size: 16.2 kB
# Stop if status code other than 200.
stop_for_status(nytimes.movies)
# Content for the JSON data.
nytimes.movies <-rawToChar(nytimes.movies$content)
# Read in all of the JSON data.
nytimes.movies.list <- fromJSON(nytimes.movies)
# Convert to data frame.
nytimes.movies.df <- as.data.frame(nytimes.movies.list$results)
# Display the data frame.
nytimes.movies.df
## display_title mpaa_rating critics_pick
## 1 Synonyms 1
## 2 Black and Blue R 1
## 3 Western Stars PG 1
## 4 Making Waves: The Art of Cinematic Sound 1
## 5 Burning Cane 1
## 6 The Kill Team R 0
## 7 Farming R 0
## 8 The Great Alaskan Race PG 0
## 9 Portals 0
## 10 The Gallows Act II R 0
## 11 The Current War: Director's Cut PG-13 0
## 12 Paradise Hills 0
## 13 Frankie PG-13 0
## 14 The Elephant Queen PG 1
## 15 By the Grace of God 1
## 16 The Cave PG-13 1
## 17 Wounds R 0
## 18 Jojo Rabbit PG-13 0
## 19 Kinetta 0
## 20 Maleficent: Mistress of Evil PG 0
## byline
## 1 MANOHLA DARGIS
## 2 A.O. SCOTT
## 3 KEN JAWOROWSKI
## 4 GLENN KENNY
## 5 GLENN KENNY
## 6 BEN KENIGSBERG
## 7 BEN KENIGSBERG
## 8 TEO BUGBEE
## 9 BEN KENIGSBERG
## 10 GLENN KENNY
## 11 KEN JAWOROWSKI
## 12 MANOHLA DARGIS
## 13 A.O. SCOTT
## 14 KEN JAWOROWSKI
## 15 GLENN KENNY
## 16 BEN KENIGSBERG
## 17 HELEN T. VERONGOS
## 18 A.O. SCOTT
## 19 BEN KENIGSBERG
## 20 MANOHLA DARGIS
## headline
## 1 ‘Synonyms’ Review: Brilliant. Relentless. Comic. Tragic.
## 2 ‘Black and Blue’ Review: A Cop Thriller for Our Age of Dread
## 3 ‘Western Stars’ Review: Bruce Springsteen and Broken Cowboys
## 4 ‘Making Waves’ Review: How Sound in Cinema Moves Us
## 5 ‘Burning Cane’ Review: Poverty and Despair in Rural Louisiana
## 6 ‘The Kill Team’ Review: Bullying on the Battlefield
## 7 ‘Farming’ Review: A Young Life of Self-Loathing
## 8 ‘The Great Alaskan Race’ Review: A Historic Sled Rescue Turned to Mush
## 9 ‘Portals’ Review: Snoozing Through Another Dimension
## 10 ‘The Gallows Act II’ Review: The Play’s the Thing (That Kills)
## 11 ‘The Current War’ Review: Edison vs. Westinghouse, Down to the Wire
## 12 ‘Paradise Hills’ Review: Caged Birds Singing, Maybe Escaping
## 13 ‘Frankie’ Review: Troubled in Paradise
## 14 ‘The Elephant Queen’ Review: Magnificent Images of Majestic Animals
## 15 ‘By the Grace of God’ Review: A Devastating Film About Survivors of Abuse
## 16 ‘The Cave’ Review: Do No Harm, for as Long as Possible
## 17 ‘Wounds’ Review: He Sees Dead People
## 18 ‘Jojo Rabbit’ Review: The Third Reich Wasn’t All Fun and Games
## 19 ‘Kinetta’ Review: Cryptic Seeds of Yorgos Lanthimos’s Imagery
## 20 ‘Maleficent: Mistress of Evil’ Review: Sleep, Sleep, My Lovelies
## summary_short
## 1 In this scorching movie from Nadav Lapid, a young Israeli flees to Paris and tries to transform into a Frenchman. It goes badly.
## 2 Naomie Harris plays a rookie running from bad police officers and drug dealers in Deon Taylor’s violent, astute film.
## 3 This concert film, directed by the singer and Thom Zimny, puts Bruce in a barn with an orchestra to make some magic.
## 4 A documentary provides vivid examples of the power of audio in a motion picture.
## 5 The director Phillip Youmans completed this, his first feature, while still in his teens. It feels like the work of an older, and fully formed, artist.
## 6 Alexander Skarsgard stars in a film based on the murders of Afghan civilians by American soldiers nearly a decade ago.
## 7 Adewale Akinnuoye-Agbaje looks at the impact of a British system that placed the children of African immigrants with Caucasian foster families.
## 8 Brian Presley’s film squanders the dramatic ingredients of the early-20th-century sledding adventure it’s based on.
## 9 In this science fiction anthology, encounters with interdimensional beings prove to be a complete a waste of time.
## 10 Life gets a bit too dramatic for a high school drama student in this horror film.
## 11 The film, which follows the race to bring electricity to American cities, stars Benedict Cumberbatch and Michael Shannon.
## 12 In this dystopian tale, a private treatment center turns privileged young women into smilingly compliant stereotypes.
## 13 Isabelle Huppert leads an impressive cast on a glum trip in Ira Sachs’s new film.
## 14 In footage shot over several years, this documentary follows a herd of elephants across the Kenyan savanna.
## 15 The often irreverent French director François Ozon gets serious with a fact-based story about a group of men who were childhood victims of a pedophile priest.
## 16 Feras Fayyad’s new documentary takes viewers into a subterranean Syrian hospital, as warplanes rumble overhead and bombings rattle the walls.
## 17 Armie Hammer plays a New Orleans bartender who quickly loses his friendly veneer when a spooky cellphone takes over his life.
## 18 Taika Waititi’s new film mixes farce, fantasy and drama in a Nazi-era coming-of-age story.
## 19 Set around a Greek seaside resort, the now-acclaimed director’s 2005 movie bears inklings of ideas he would explore more fully later.
## 20 Angelina Jolie returns as the powerful, dangerous fairy in this tame, disappointing follow-up to the 2014 revisionist hit.
## publication_date opening_date date_updated link.type
## 1 2019-10-24 2019-10-25 2019-10-27 16:44:22 article
## 2 2019-10-24 2019-10-25 2019-10-27 16:44:22 article
## 3 2019-10-24 2019-10-25 2019-10-27 16:44:21 article
## 4 2019-10-24 2019-10-25 2019-10-27 16:44:21 article
## 5 2019-10-24 2019-10-25 2019-10-27 16:44:20 article
## 6 2019-10-24 2019-10-25 2019-10-24 17:56:02 article
## 7 2019-10-24 <NA> 2019-10-27 16:44:21 article
## 8 2019-10-24 2019-10-25 2019-10-27 16:44:20 article
## 9 2019-10-24 2019-10-25 2019-10-24 11:04:03 article
## 10 2019-10-24 2019-10-25 2019-10-27 16:44:19 article
## 11 2019-10-24 2019-10-25 2019-10-27 16:44:19 article
## 12 2019-10-23 2019-10-25 2019-10-27 16:44:18 article
## 13 2019-10-23 2019-10-25 2019-10-27 16:44:18 article
## 14 2019-10-17 <NA> 2019-10-25 16:44:02 article
## 15 2019-10-17 2019-10-18 2019-10-27 16:44:15 article
## 16 2019-10-17 2019-10-18 2019-10-25 16:44:02 article
## 17 2019-10-17 2019-10-18 2019-10-17 22:28:03 article
## 18 2019-10-17 2019-10-18 2019-10-27 16:44:17 article
## 19 2019-10-17 2019-10-18 2019-10-27 16:44:17 article
## 20 2019-10-17 2019-10-18 2019-10-27 16:44:17 article
## link.url
## 1 http://www.nytimes.com/2019/10/24/movies/synonyms-review.html
## 2 http://www.nytimes.com/2019/10/24/movies/black-and-blue-review.html
## 3 http://www.nytimes.com/2019/10/24/movies/western-stars-review.html
## 4 http://www.nytimes.com/2019/10/24/movies/making-waves-the-art-of-cinematic-sound-review.html
## 5 http://www.nytimes.com/2019/10/24/movies/burning-cane-review.html
## 6 http://www.nytimes.com/2019/10/24/movies/the-kill-team-review.html
## 7 http://www.nytimes.com/2019/10/24/movies/farming-review.html
## 8 http://www.nytimes.com/2019/10/24/movies/the-great-alaskan-race-review.html
## 9 http://www.nytimes.com/2019/10/24/movies/portals-review.html
## 10 http://www.nytimes.com/2019/10/24/movies/the-gallows-act-two-review.html
## 11 http://www.nytimes.com/2019/10/24/movies/the-current-war-review.html
## 12 http://www.nytimes.com/2019/10/23/movies/paradise-hills-review.html
## 13 http://www.nytimes.com/2019/10/23/movies/frankie-review.html
## 14 http://www.nytimes.com/2019/10/17/movies/the-elephant-queen-review.html
## 15 http://www.nytimes.com/2019/10/17/movies/by-the-grace-of-god-review.html
## 16 http://www.nytimes.com/2019/10/17/movies/the-cave-review.html
## 17 http://www.nytimes.com/2019/10/17/movies/wounds-review.html
## 18 http://www.nytimes.com/2019/10/17/movies/jojo-rabbit-review.html
## 19 http://www.nytimes.com/2019/10/17/movies/kinetta-review.html
## 20 http://www.nytimes.com/2019/10/17/movies/maleficent-mistress-of-evil-review.html
## link.suggested_link_text
## 1 Read the New York Times Review of Synonyms
## 2 Read the New York Times Review of Black and Blue
## 3 Read the New York Times Review of Western Stars
## 4 Read the New York Times Review of Making Waves: The Art of Cinematic Sound
## 5 Read the New York Times Review of Burning Cane
## 6 Read the New York Times Review of The Kill Team
## 7 Read the New York Times Review of Farming
## 8 Read the New York Times Review of The Great Alaskan Race
## 9 Read the New York Times Review of Portals
## 10 Read the New York Times Review of The Gallows Act II
## 11 Read the New York Times Review of The Current War: Director's Cut
## 12 Read the New York Times Review of Paradise Hills
## 13 Read the New York Times Review of Frankie
## 14 Read the New York Times Review of The Elephant Queen
## 15 Read the New York Times Review of By the Grace of God
## 16 Read the New York Times Review of The Cave
## 17 Read the New York Times Review of Wounds
## 18 Read the New York Times Review of Jojo Rabbit
## 19 Read the New York Times Review of Kinetta
## 20 Read the New York Times Review of Maleficent: Mistress of Evil
## multimedia.type
## 1 mediumThreeByTwo210
## 2 mediumThreeByTwo210
## 3 mediumThreeByTwo210
## 4 mediumThreeByTwo210
## 5 mediumThreeByTwo210
## 6 mediumThreeByTwo210
## 7 mediumThreeByTwo210
## 8 mediumThreeByTwo210
## 9 mediumThreeByTwo210
## 10 mediumThreeByTwo210
## 11 mediumThreeByTwo210
## 12 mediumThreeByTwo210
## 13 mediumThreeByTwo210
## 14 mediumThreeByTwo210
## 15 mediumThreeByTwo210
## 16 mediumThreeByTwo210
## 17 mediumThreeByTwo210
## 18 mediumThreeByTwo210
## 19 mediumThreeByTwo210
## 20 mediumThreeByTwo210
## multimedia.src
## 1 https://static01.nyt.com/images/2019/10/24/arts/24synonyms/merlin_162980427_b8788cef-d2c4-4e28-a9a5-7a2f1539577a-mediumThreeByTwo210.jpg
## 2 https://static01.nyt.com/images/2019/10/25/arts/24blackandblue/merlin_162979524_8fe68107-5e63-4c42-aab1-e951f9dde0e7-mediumThreeByTwo210.jpg
## 3 https://static01.nyt.com/images/2019/10/24/arts/western1/merlin_162980691_01b11a6f-d4c0-48de-a1a3-bb081a6082d5-mediumThreeByTwo210.jpg
## 4 https://static01.nyt.com/images/2019/10/25/arts/24makingwaves/24makingwaves-mediumThreeByTwo210.jpg
## 5 https://static01.nyt.com/images/2019/10/25/arts/24burning/merlin_162979698_0fef3cbf-1f57-4374-a5d4-8da952532c16-mediumThreeByTwo210.jpg
## 6 https://static01.nyt.com/images/2019/10/24/arts/24killteam/merlin_162980196_c2a146f1-5a88-4e2e-bec6-19dfd36fa254-mediumThreeByTwo210.jpg
## 7 https://static01.nyt.com/images/2019/10/25/arts/24FARMING/merlin_162979812_4a924b7f-40bf-4d89-b781-425e0e7610fd-mediumThreeByTwo210.jpg
## 8 https://static01.nyt.com/images/2019/10/24/arts/24greatalaskan/24greatalaskan-mediumThreeByTwo210.jpg
## 9 https://static01.nyt.com/images/2019/10/22/arts/portals1/portals1-mediumThreeByTwo210.jpg
## 10 https://static01.nyt.com/images/2019/10/22/arts/gallows1/gallows1-mediumThreeByTwo210.jpg
## 11 https://static01.nyt.com/images/2019/10/23/arts/current2/current2-mediumThreeByTwo210.jpg
## 12 https://static01.nyt.com/images/2019/10/25/arts/23paradise-1/merlin_162980316_f2923866-4de0-4164-94b6-f0f202fa4758-mediumThreeByTwo210.jpg
## 13 https://static01.nyt.com/images/2019/10/25/arts/25frankie/merlin_162979869_c60d9411-18eb-430d-be8c-3f5d2fb42983-mediumThreeByTwo210.jpg
## 14 https://static01.nyt.com/images/2019/10/18/arts/17elephantqueen-art/merlin_162491211_576ddd0e-4389-4a2d-8521-3f5c092184ed-mediumThreeByTwo210.jpg
## 15 https://static01.nyt.com/images/2019/10/18/arts/17graceofgod-art/merlin_162489012_de91ad91-3748-445c-b3ea-c3c24e565a96-mediumThreeByTwo210.jpg
## 16 https://static01.nyt.com/images/2019/10/18/arts/17thecave-art/merlin_162490917_4443d34d-2a44-44d8-b04d-673b56d8894a-mediumThreeByTwo210.jpg
## 17 https://static01.nyt.com/images/2019/10/17/arts/17WOUNDS/17WOUNDS-mediumThreeByTwo210.jpg
## 18 https://static01.nyt.com/images/2019/10/17/arts/17jojorabbit/17jojorabbit-mediumThreeByTwo210.jpg
## 19 https://static01.nyt.com/images/2019/10/17/arts/17kinetta/merlin_162581646_1afd1b09-388e-4662-adc6-8655e3bcf70e-mediumThreeByTwo210.jpg
## 20 https://static01.nyt.com/images/2019/10/18/arts/17maleficentpix1/17maleficentpix1-mediumThreeByTwo210.jpg
## multimedia.width multimedia.height
## 1 210 140
## 2 210 140
## 3 210 140
## 4 210 140
## 5 210 140
## 6 210 140
## 7 210 140
## 8 210 140
## 9 210 140
## 10 210 140
## 11 210 140
## 12 210 140
## 13 210 140
## 14 210 140
## 15 210 140
## 16 210 140
## 17 210 140
## 18 210 140
## 19 210 140
## 20 210 140
# Remove some columns.
nytimes.movies.df <- nytimes.movies.df[, -c(6,8,9,11)]
# Update columns name.
nytimes.movies.df <- nytimes.movies.df %>% rename("Movie Titles"="display_title", "Rating"="mpaa_rating", "Critics Pick"="critics_pick", "Reviewer"="byline", "Review Headline"="headline", "Publication Date"="publication_date", "Link"="link")
# Reorder the publication date column to first column.
nytimes.movies.df <- nytimes.movies.df %>% select('Publication Date', everything())
# Extract the link URL.
nytimes.movies.df <- nytimes.movies.df %>% mutate(Link=unlist(str_extract_all(nytimes.movies.df$Link, "http\\:.*?\\.htm")))
## Warning in stri_extract_all_regex(string, pattern, simplify = simplify, :
## argument is not an atomic vector; coercing
# Replace empty vector components with NA.
is.na(nytimes.movies.df) <- nytimes.movies.df == ""
# Display the final dataframe.
nytimes.movies.df
## Publication Date Movie Titles Rating
## 1 2019-10-24 Synonyms <NA>
## 2 2019-10-24 Black and Blue R
## 3 2019-10-24 Western Stars PG
## 4 2019-10-24 Making Waves: The Art of Cinematic Sound <NA>
## 5 2019-10-24 Burning Cane <NA>
## 6 2019-10-24 The Kill Team R
## 7 2019-10-24 Farming R
## 8 2019-10-24 The Great Alaskan Race PG
## 9 2019-10-24 Portals <NA>
## 10 2019-10-24 The Gallows Act II R
## 11 2019-10-24 The Current War: Director's Cut PG-13
## 12 2019-10-23 Paradise Hills <NA>
## 13 2019-10-23 Frankie PG-13
## 14 2019-10-17 The Elephant Queen PG
## 15 2019-10-17 By the Grace of God <NA>
## 16 2019-10-17 The Cave PG-13
## 17 2019-10-17 Wounds R
## 18 2019-10-17 Jojo Rabbit PG-13
## 19 2019-10-17 Kinetta <NA>
## 20 2019-10-17 Maleficent: Mistress of Evil PG
## Critics Pick Reviewer
## 1 1 MANOHLA DARGIS
## 2 1 A.O. SCOTT
## 3 1 KEN JAWOROWSKI
## 4 1 GLENN KENNY
## 5 1 GLENN KENNY
## 6 0 BEN KENIGSBERG
## 7 0 BEN KENIGSBERG
## 8 0 TEO BUGBEE
## 9 0 BEN KENIGSBERG
## 10 0 GLENN KENNY
## 11 0 KEN JAWOROWSKI
## 12 0 MANOHLA DARGIS
## 13 0 A.O. SCOTT
## 14 1 KEN JAWOROWSKI
## 15 1 GLENN KENNY
## 16 1 BEN KENIGSBERG
## 17 0 HELEN T. VERONGOS
## 18 0 A.O. SCOTT
## 19 0 BEN KENIGSBERG
## 20 0 MANOHLA DARGIS
## Review Headline
## 1 ‘Synonyms’ Review: Brilliant. Relentless. Comic. Tragic.
## 2 ‘Black and Blue’ Review: A Cop Thriller for Our Age of Dread
## 3 ‘Western Stars’ Review: Bruce Springsteen and Broken Cowboys
## 4 ‘Making Waves’ Review: How Sound in Cinema Moves Us
## 5 ‘Burning Cane’ Review: Poverty and Despair in Rural Louisiana
## 6 ‘The Kill Team’ Review: Bullying on the Battlefield
## 7 ‘Farming’ Review: A Young Life of Self-Loathing
## 8 ‘The Great Alaskan Race’ Review: A Historic Sled Rescue Turned to Mush
## 9 ‘Portals’ Review: Snoozing Through Another Dimension
## 10 ‘The Gallows Act II’ Review: The Play’s the Thing (That Kills)
## 11 ‘The Current War’ Review: Edison vs. Westinghouse, Down to the Wire
## 12 ‘Paradise Hills’ Review: Caged Birds Singing, Maybe Escaping
## 13 ‘Frankie’ Review: Troubled in Paradise
## 14 ‘The Elephant Queen’ Review: Magnificent Images of Majestic Animals
## 15 ‘By the Grace of God’ Review: A Devastating Film About Survivors of Abuse
## 16 ‘The Cave’ Review: Do No Harm, for as Long as Possible
## 17 ‘Wounds’ Review: He Sees Dead People
## 18 ‘Jojo Rabbit’ Review: The Third Reich Wasn’t All Fun and Games
## 19 ‘Kinetta’ Review: Cryptic Seeds of Yorgos Lanthimos’s Imagery
## 20 ‘Maleficent: Mistress of Evil’ Review: Sleep, Sleep, My Lovelies
## Link
## 1 http://www.nytimes.com/2019/10/24/movies/synonyms-review.htm
## 2 http://www.nytimes.com/2019/10/24/movies/black-and-blue-review.htm
## 3 http://www.nytimes.com/2019/10/24/movies/western-stars-review.htm
## 4 http://www.nytimes.com/2019/10/24/movies/making-waves-the-art-of-cinematic-sound-review.htm
## 5 http://www.nytimes.com/2019/10/24/movies/burning-cane-review.htm
## 6 http://www.nytimes.com/2019/10/24/movies/the-kill-team-review.htm
## 7 http://www.nytimes.com/2019/10/24/movies/farming-review.htm
## 8 http://www.nytimes.com/2019/10/24/movies/the-great-alaskan-race-review.htm
## 9 http://www.nytimes.com/2019/10/24/movies/portals-review.htm
## 10 http://www.nytimes.com/2019/10/24/movies/the-gallows-act-two-review.htm
## 11 http://www.nytimes.com/2019/10/24/movies/the-current-war-review.htm
## 12 http://www.nytimes.com/2019/10/23/movies/paradise-hills-review.htm
## 13 http://www.nytimes.com/2019/10/23/movies/frankie-review.htm
## 14 http://www.nytimes.com/2019/10/17/movies/the-elephant-queen-review.htm
## 15 http://www.nytimes.com/2019/10/17/movies/by-the-grace-of-god-review.htm
## 16 http://www.nytimes.com/2019/10/17/movies/the-cave-review.htm
## 17 http://www.nytimes.com/2019/10/17/movies/wounds-review.htm
## 18 http://www.nytimes.com/2019/10/17/movies/jojo-rabbit-review.htm
## 19 http://www.nytimes.com/2019/10/17/movies/kinetta-review.htm
## 20 http://www.nytimes.com/2019/10/17/movies/maleficent-mistress-of-evil-review.htm