The task is to 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.
I will store the api-key value in an environment variable by using Sys.setenv
## Warning: package 'httr' was built under R version 4.0.3
## Warning: package 'jsonlite' was built under R version 4.0.3
To connect to the API, we append the api-key as a query string value to the API URL.
We begin by taking a look at the data provided by the API:
## display_title mpaa_rating critics_pick byline
## Length:20 Length:20 Min. :1 Length:20
## Class :character Class :character 1st Qu.:1 Class :character
## Mode :character Mode :character Median :1 Mode :character
## Mean :1
## 3rd Qu.:1
## Max. :1
## headline summary_short publication_date opening_date
## Length:20 Length:20 Length:20 Length:20
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## date_updated
## Length:20
## Class :character
## Mode :character
##
##
##
## link.type link.url link.suggested_link_text
## Length:20 Length:20 Length:20
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## multimedia.type multimedia.src multimedia.width multimedia.height
## Length:20 Length:20 Min. :210 Min. :140
## Class :character Class :character 1st Qu.:210 1st Qu.:140
## Mode :character Mode :character Median :210 Median :140
## NA NA Mean :210 Mean :140
## NA NA 3rd Qu.:210 3rd Qu.:140
## NA NA Max. :210 Max. :140
## Warning in `[<-.data.frame`(`*tmp*`, , j, value = structure(list(type =
## structure(c("article", : provided 3 variables to replace 1 variables
## Warning in `[<-.data.frame`(`*tmp*`, , j, value = structure(list(type =
## structure(c("mediumThreeByTwo210", : provided 4 variables to replace 1 variables
display_title | mpaa_rating | critics_pick | byline | headline | summary_short | publication_date | opening_date | date_updated | link | multimedia |
---|---|---|---|---|---|---|---|---|---|---|
What the Constitution Means to Me | 1 | Elisabeth Vincentelli | ‘What the Constitution Means to Me’ Review: Pursuits of Happiness | The timing could not be better for Heidi Schreck’s affecting play about the Constitution’s impact on our daily lives, now streaming on Amazon. | 2020-10-22 | 2020-10-16 | 2020-10-22 17:12:02 | article | mediumThreeByTwo210 | |
Synchronic | R | 1 | Glenn Kenny | ‘Synchronic’ Review: Twisted, Trippy Trips Through Time | The filmmakers Justin Benson and Aaron Moorhead bend reality in this drug-fueled sci-fi horror. | 2020-10-22 | 2020-10-23 | 2020-10-24 16:44:16 | article | mediumThreeByTwo210 |
Ham on Rye | 1 | Glenn Kenny | ‘Ham on Rye’ Review: Coming of Age, With Existential Unease | Tyler Taormina’s debut film starts in the vein of classic high-school comedies until it turns toward a dark surrealism. | 2020-10-22 | NA | 2020-10-22 11:04:07 | article | mediumThreeByTwo210 | |
Belly of the Beast | 1 | Lovia Gyarkye | ‘Belly of the Beast’ Review: Fighting for Incarcerated Women | Erika Cohn’s new documentary focuses on the sterilization of women in California prisons, and the battle for a law against the practice. | 2020-10-15 | NA | 2020-10-15 16:02:02 | article | mediumThreeByTwo210 | |
White Riot | 1 | Glenn Kenny | ‘White Riot’ Review: When Punk’s Stars Banded Against Racism | Rubika Shah’s documentary about the British organization Rock Against Racism is a compelling depiction of political organizing in the 1970s. | 2020-10-15 | NA | 2020-10-15 11:04:06 | article | mediumThreeByTwo210 | |
Martin Eden | 1 | Manohla Dargis | ‘Martin Eden’ Review: Reading and Writing His Way Out of the Pit | In this bold adaptation of the Jack London novel, a young writer suffers, fights and pays as he stands alone against the world. | 2020-10-15 | 2020-10-16 | 2020-10-15 11:04:08 | article | mediumThreeByTwo210 |
Because we used the Movies API to only get critic’s picks, we see the pick column value is always one.
Let’s count the movies by rating:
movies_ratings <- my_data_frame %>%
count(mpaa_rating) %>%
mutate(p = n /sum(n))
movies_ratings$mpaa_rating[1] <- "No Rating"
knitr::kable(movies_ratings)
mpaa_rating | n | p |
---|---|---|
No Rating | 13 | 0.65 |
PG | 1 | 0.05 |
PG-13 | 2 | 0.10 |
R | 4 | 0.20 |
It appears that most of the NY Times Critic’s picks are not rated by the MPAA. Further analysis could be done to try to infer the probability of a movie being picked by a critic based on its description (to try to determine its genre and other descriptive features).
…