Data607-Assignment9
Overview
The goal for this assignment is to connect and retrieve JSON data using the New York Times Movie Review API. Once connected, we want to put this data into a dataframe and view the dataframe.
Necessary libraries:
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
##
## group_rows
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Connect to API
Using the NYT Movie Review API Key, which I signed up for on the NYT website, we will retrieve ALL movie review data and critic review data using the function fromJSON
options(stringAsFactors = FALSE)
movie_review_url <- str_c('https://api.nytimes.com/svc/movies/v2/reviews/all.json?order=by-opening-date&api-key=',api_key)
movie_raw <- fromJSON(movie_review_url,flatten=TRUE)
critic_review_url <- str_c('https://api.nytimes.com/svc/movies/v2/critics/all.json?order=by-opening-date&api-key=',api_key)
critic_raw <- fromJSON(critic_review_url,flatten=TRUE)View Raw Data
movie_reviews <- as.data.frame(movie_raw)
kable(head(movie_reviews,2)) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>% scroll_box(width = "125%") | status | copyright | has_more | num_results | results.display_title | results.mpaa_rating | results.critics_pick | results.byline | results.headline | results.summary_short | results.publication_date | results.opening_date | results.date_updated | results.link.type | results.link.url | results.link.suggested_link_text | results.multimedia.type | results.multimedia.src | results.multimedia.width | results.multimedia.height |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OK | Copyright (c) 2020 The New York Times Company. All Rights Reserved. | TRUE | 20 | The State Against Mandela and the Others | 1 | Glenn Kenny | ‘The State Against Mandela and the Others’ Review: Sounds of Injustice | Nelson Mandela’s trial nearly 60 years ago was not filmed, but the words spoken still echo loudly. | 2020-02-18 | NA | 2020-02-28 17:44:01 | article | http://www.nytimes.com/2020/02/18/movies/the-state-against-mandela-and-the-others-review.html | Read the New York Times Review of The State Against Mandela and the Others | mediumThreeByTwo210 | https://static01.nyt.com/images/2020/02/18/arts/18thestate1/18thestate1-mediumThreeByTwo210.jpg | 210 | 140 | |
| OK | Copyright (c) 2020 The New York Times Company. All Rights Reserved. | TRUE | 20 | I Wish I Knew | 1 | Manohla Dargis | ‘I Wish I Knew’ Review: A Melancholy Master’s Portrait of a City | In this elegiac documentary, the director Jia Zhangke explores Shanghai through its people, stories and soaring cranes. | 2020-01-23 | NA | 2020-02-21 17:44:01 | article | http://www.nytimes.com/2020/01/23/movies/i-wish-i-knew-review.html | Read the New York Times Review of I Wish I Knew | mediumThreeByTwo210 | https://static01.nyt.com/images/2020/01/24/arts/00IwishIknew-1/00IwishIknew-1-mediumThreeByTwo210.jpg | 210 | 140 |
critic_reviews <- as.data.frame(critic_raw)
kable(head(critic_reviews,2)) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>% scroll_box(width = "125%") | status | copyright | num_results | results.display_name | results.sort_name | results.status | results.bio | results.seo_name | results.multimedia.resource.type | results.multimedia.resource.src | results.multimedia.resource.height | results.multimedia.resource.width | results.multimedia.resource.credit |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OK | Copyright (c) 2020 The New York Times Company. All Rights Reserved. | 82 | A. O. Scott | A. O. Scott | full-time | A. O. Scott joined The New York Times as a film critic in January 2000, and was named a chief critic in 2004. Previously, Mr. Scott had been the lead Sunday book reviewer for Newsday and a frequent contributor to Slate, The New York Review of Books, and many other publications. <br/><br/> In the 1990s he served on the editorial staffs of Lingua Franca and The New York Review of Books. He also edited “A Bolt from the Blue and Other Essays,” a collection by Mary McCarthy, which was published by The New York Review of Books in 2002. <br/><br/> Mr. Scott was a finalist for the Pulitzer Prize in Criticism in 2010, the same year he served as co-host (with Michael Phillips of the Chicago Tribune) on the last season of “At the Movies,” the syndicated film-reviewing program started by Roger Ebert and Gene Siskel. <br/><br/> A frequent presence on radio and television, Mr. Scott is Distinguished Professor of Film Criticism at Wesleyan University and the author of Better Living Through Criticism, forthcoming in 2016 from The Penguin Press. A collection of his film writing will be published by Penguin in 2017. <br/><br/> He lives in Brooklyn with his family. | A-O-Scott | image | http://static01.nyt.com/images/2015/10/07/topics/ao-scott/ao-scott-articleInline.jpg | 163 | 220 | Earl Wilson/<br/>The New York Times |
| OK | Copyright (c) 2020 The New York Times Company. All Rights Reserved. | 82 | Manohla Dargis | Manohla Dargis | full-time | Manohla Dargis is the co-chief film critic for The Times, where she started in 2004. She has also written for The Los Angeles Times, where she was a chief film critic, and for the LA Weekly, where she was both a film critic and the film editor. She lives in Los Angeles. | Manohla-Dargis | NA | NA | NA | NA | NA |
Cleaner Data
Let’s look at a smaller subset of columns to really get a look at the data
movie_reviews_subset <- select(movie_reviews,results.display_title,results.mpaa_rating,results.byline,results.headline,results.summary_short,results.publication_date,results.link.type,results.link.url)
colnames(movie_reviews_subset) <- c('Display.Title','MPAA.Rating','Byline','Headline','Summary.Short','Publication.Date','Link.Type','Link.URL')
kable(head(movie_reviews_subset,5)) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>% scroll_box(width = "125%") | Display.Title | MPAA.Rating | Byline | Headline | Summary.Short | Publication.Date | Link.Type | Link.URL |
|---|---|---|---|---|---|---|---|
| The State Against Mandela and the Others | Glenn Kenny | ‘The State Against Mandela and the Others’ Review: Sounds of Injustice | Nelson Mandela’s trial nearly 60 years ago was not filmed, but the words spoken still echo loudly. | 2020-02-18 | article | http://www.nytimes.com/2020/02/18/movies/the-state-against-mandela-and-the-others-review.html | |
| I Wish I Knew | Manohla Dargis | ‘I Wish I Knew’ Review: A Melancholy Master’s Portrait of a City | In this elegiac documentary, the director Jia Zhangke explores Shanghai through its people, stories and soaring cranes. | 2020-01-23 | article | http://www.nytimes.com/2020/01/23/movies/i-wish-i-knew-review.html | |
| Les Misérables | R | Glenn Kenny | ‘Les Misérables’ Review: Injustice Still Stalks the Poor of Paris | In modern-day Montfermeil, the setting of Victor Hugo’s novel, the filmmaker Ladj Ly stages his own impassioned cry against oppression. | 2019-11-28 | article | http://www.nytimes.com/2019/11/28/movies/les-miserables-review.html |
| Redoubt | GLENN KENNY | ‘Redoubt’ Review: Diana the Huntress Manifests in Idaho | Breathtakingly beautiful and with little spoken dialogue, Matthew Barney’s film is a western that reaches for the cosmic. | 2019-10-29 | article | http://www.nytimes.com/2019/10/29/movies/redoubt-review.html | |
| The Elephant Queen | PG | KEN JAWOROWSKI | ‘The Elephant Queen’ Review: Magnificent Images of Majestic Animals | In footage shot over several years, this documentary follows a herd of elephants across the Kenyan savanna. | 2019-10-17 | article | http://www.nytimes.com/2019/10/17/movies/the-elephant-queen-review.html |
critic_reviews_subset <- select(critic_reviews,results.display_name,results.sort_name,results.status,results.bio,results.seo_name)
colnames(critic_reviews_subset) <- c('Display.Name','Sort.Name','Status','Bio','SEO.Name')
kable(head(critic_reviews_subset,5)) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>% scroll_box(width = "125%") | Display.Name | Sort.Name | Status | Bio | SEO.Name |
|---|---|---|---|---|
| A. O. Scott | A. O. Scott | full-time | A. O. Scott joined The New York Times as a film critic in January 2000, and was named a chief critic in 2004. Previously, Mr. Scott had been the lead Sunday book reviewer for Newsday and a frequent contributor to Slate, The New York Review of Books, and many other publications. <br/><br/> In the 1990s he served on the editorial staffs of Lingua Franca and The New York Review of Books. He also edited “A Bolt from the Blue and Other Essays,” a collection by Mary McCarthy, which was published by The New York Review of Books in 2002. <br/><br/> Mr. Scott was a finalist for the Pulitzer Prize in Criticism in 2010, the same year he served as co-host (with Michael Phillips of the Chicago Tribune) on the last season of “At the Movies,” the syndicated film-reviewing program started by Roger Ebert and Gene Siskel. <br/><br/> A frequent presence on radio and television, Mr. Scott is Distinguished Professor of Film Criticism at Wesleyan University and the author of Better Living Through Criticism, forthcoming in 2016 from The Penguin Press. A collection of his film writing will be published by Penguin in 2017. <br/><br/> He lives in Brooklyn with his family. | A-O-Scott |
| Manohla Dargis | Manohla Dargis | full-time | Manohla Dargis is the co-chief film critic for The Times, where she started in 2004. She has also written for The Los Angeles Times, where she was a chief film critic, and for the LA Weekly, where she was both a film critic and the film editor. She lives in Los Angeles. | Manohla-Dargis |
| Stephen Holden | Stephen Holden | full-time | Stephen Holden is a film and music critic for The Times; he joined the culture staff in 1988. Prior to that, he was a pop music critic and journalist for Rolling Stone, The Village Voice, and numerous other magazines and anthologies. Drawing on his experiences as a journalist and record executive, he wrote a satirical novel about the record business, “Triple Platinum,” that was published in 1980 by Dell Books. In 1986, he won a Grammy with six other writers for Best Album Notes for “The Voice: The Columbia Years, a Frank Sinatra Anthology.” Born July 18, 1941, Mr. Holden graduated from Yale University in 1963 with a Bachelor of Arts degree in English and was elected Class Poet. | Stephen-Holden |
| Renata Adler | Adler, Renata | part-time | Renata-Adler | |
| Mordaunt Hall | Hall, Mordaunt | part-time | Mordaunt-Hall |
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.