For assignment 6, we were asked to use the New York Times API to import data. I chose the Movie Reviews API. I passed in the key through a text file on my local machine just so the key wouldn't be public in RPubs/Github.
NYTIMES_KEY <- readLines("NYTIMES_KEY.txt")
## Warning in readLines("NYTIMES_KEY.txt"): incomplete final line found on
## 'NYTIMES_KEY.txt'
#https://api.nytimes.com/svc/archive/v1/2019/1.json?api-key=yourkey
url <- paste0("https://api.nytimes.com/svc/movies/v2/critics/full-time.json?api-key=", NYTIMES_KEY)
nyt <- GET(url)
nyt
## Response [https://api.nytimes.com/svc/movies/v2/critics/full-time.json?api-key=J0F0Y33Rv3ODWinQI1E8PRPFiliqHu40]
## Date: 2022-10-31 02:40
## Status: 200
## Content-Type: application/json; charset=utf-8
## Size: 3.12 kB
details<-content(nyt, "parse")
details
## $status
## [1] "OK"
##
## $copyright
## [1] "Copyright (c) 2022 The New York Times Company. All Rights Reserved."
##
## $num_results
## [1] 3
##
## $results
## $results[[1]]
## $results[[1]]$display_name
## [1] "A. O. Scott"
##
## $results[[1]]$sort_name
## [1] "A. O. Scott"
##
## $results[[1]]$status
## [1] "full-time"
##
## $results[[1]]$bio
## [1] "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. \n<br/><br/>\nIn 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. \n<br/><br/>\nMr. 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.\n<br/><br/>\nA 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. \n<br/><br/>\nHe lives in Brooklyn with his family."
##
## $results[[1]]$seo_name
## [1] "A-O-Scott"
##
## $results[[1]]$multimedia
## $results[[1]]$multimedia$resource
## $results[[1]]$multimedia$resource$type
## [1] "image"
##
## $results[[1]]$multimedia$resource$src
## [1] "http://static01.nyt.com/images/2015/10/07/topics/ao-scott/ao-scott-articleInline.jpg"
##
## $results[[1]]$multimedia$resource$height
## [1] 163
##
## $results[[1]]$multimedia$resource$width
## [1] 220
##
## $results[[1]]$multimedia$resource$credit
## [1] "Earl Wilson/<br/>The New York Times"
##
##
##
##
## $results[[2]]
## $results[[2]]$display_name
## [1] "Manohla Dargis"
##
## $results[[2]]$sort_name
## [1] "Manohla Dargis"
##
## $results[[2]]$status
## [1] "full-time"
##
## $results[[2]]$bio
## [1] "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."
##
## $results[[2]]$seo_name
## [1] "Manohla-Dargis"
##
## $results[[2]]$multimedia
## NULL
##
##
## $results[[3]]
## $results[[3]]$display_name
## [1] "Stephen Holden"
##
## $results[[3]]$sort_name
## [1] "Stephen Holden"
##
## $results[[3]]$status
## [1] "full-time"
##
## $results[[3]]$bio
## [1] "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."
##
## $results[[3]]$seo_name
## [1] "Stephen-Holden"
##
## $results[[3]]$multimedia
## $results[[3]]$multimedia$resource
## $results[[3]]$multimedia$resource$type
## [1] "image"
##
## $results[[3]]$multimedia$resource$src
## [1] "http://nytimes.com/images/2007/01/05/movies/sholden.163.jpg"
##
## $results[[3]]$multimedia$resource$height
## [1] 163
##
## $results[[3]]$multimedia$resource$width
## [1] 220
##
## $results[[3]]$multimedia$resource$credit
## [1] "Brent Murray/<br>NYTimes.com"
I made new dataframes for the bio, display_name and status.
names(details)
## [1] "status" "copyright" "num_results" "results"
bio<-as.data.frame(details$results[[1]]$bio)
bio
## details$results[[1]]$bio
## 1 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. \n<br/><br/>\nIn 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. \n<br/><br/>\nMr. 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.\n<br/><br/>\nA 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. \n<br/><br/>\nHe lives in Brooklyn with his family.
critic<-as.data.frame(details$results[[3]]$display_name)
critic
## details$results[[3]]$display_name
## 1 Stephen Holden
status<-as.data.frame(details$results[[3]]$status)
status
## details$results[[3]]$status
## 1 full-time
Then, I used cbind() to combine the 3 dataframes I made.
critic_df <-grades_updated <- cbind(critic, status, bio)
critic_df
## details$results[[3]]$display_name details$results[[3]]$status
## 1 Stephen Holden full-time
## details$results[[1]]$bio
## 1 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. \n<br/><br/>\nIn 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. \n<br/><br/>\nMr. 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.\n<br/><br/>\nA 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. \n<br/><br/>\nHe lives in Brooklyn with his family.
Finally, I made a wordcloud of the dataframe, only because I love this visualization tool that I learned of for Project 3. This analysis has no meaning, but it shows how the word "the" is used the most frequently in the dataframe (followed by "and"), which makes sense because even in the title, "THE New York Times", there is a "the".
wordcloud(words = critic_df, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.35,colors=brewer.pal(8, "Dark2"))
## Loading required namespace: tm
I personally felt like I should go back and choose a different API (everyone from class seemed to talk about the books API), but also felt I should stick with this since I don't need to do the same thing others do.