Assignment 9

The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis You’ll need to start by signing up for an API key. Your 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.

The api data I used from NY times was on books by Stephen King. To obtained the data frame from the json file I used fromJSON function, and the class function to identify the data frame within the json file. To start, I recreated the URL link to hide my API key using the paste0 function and I hide my api key into my environment by creating a variable api_key.

api_key <- Sys.getenv("NYTIMES_API_KEY")
NYT<-"https://api.nytimes.com/svc/books/v3/reviews.json?author=Stephen+King&api-key="
Full<-paste0(NYT,api_key) #paste0 function creates a string from the NYTI and api_key with no spaces in between 
url<-fromJSON(Full, flatten= TRUE)

Book_SK<-url$results #obtaining data frame from file
class(Book_SK)
## [1] "data.frame"

Data frame

Using the data table function to create a table from the data frame.

Book_table<-data.table(Book_SK)
Book_table
##                                                                                                                       url
##                                                                                                                    <char>
##  1:                              http://www.nytimes.com/2011/11/13/books/review/11-22-63-by-stephen-king-book-review.html
##  2:                                            http://www.nytimes.com/2011/10/31/books/stephen-kings-11-23-63-review.html
##  3:                              http://www.nytimes.com/2004/01/04/books/the-quest-for-the-north-central-positronics.html
##  4:                                                  http://www.nytimes.com/1993/10/24/books/in-short-fiction-284093.html
##  5:                                     http://www.nytimes.com/2001/11/04/books/books-in-brief-fiction-poetry-851302.html
##  6:                                            http://www.nytimes.com/1990/05/13/books/armageddon-complete-and-uncut.html
##  7:                                                          http://www.nytimes.com/1990/09/02/books/scared-but-safe.html
##  8:                                          http://www.nytimes.com/1991/10/20/books/l-defending-stephen-king-075091.html
##  9:          http://www.nytimes.com/1992/06/29/books/books-of-the-times-to-be-read-in-daylight-away-from-hungry-dogs.html
## 10:                                                           http://www.nytimes.com/2002/04/14/books/the-horror-etc.html
## 11:                                                http://www.nytimes.com/1986/08/21/books/books-of-the-times-547486.html
## 12:                                                        http://www.nytimes.com/2010/11/28/books/review/Rafferty-t.html
## 13:                                                         http://www.nytimes.com/1998/09/27/books/familiar-terrors.html
## 14: http://www.nytimes.com/2002/03/18/books/books-of-the-times-storytelling-mogul-decides-to-sweep-out-odds-and-ends.html
## 15:                                                  http://www.nytimes.com/1995/07/02/books/in-short-fiction-077895.html
## 16:                      http://www.nytimes.com/2013/09/16/books/doctor-sleep-is-stephen-kings-sequel-to-the-shining.html
## 17:                         http://www.nytimes.com/2013/09/22/books/review/stephen-kings-shining-sequel-doctor-sleep.html
## 18:                                           http://www.nytimes.com/2013/06/23/books/review/joyland-by-stephen-king.html
## 19:                                                         http://www.nytimes.com/2009/11/08/books/review/JParker-t.html
## 20:                                                                   http://www.nytimes.com/2009/11/12/books/12book.html
## 21:                                                    http://www.nytimes.com/2014/11/14/books/stephen-kings-revival.html
## 22:                                             http://www.nytimes.com/2014/11/23/books/review/stephen-kings-revival.html
## 23:                                                         http://www.nytimes.com/2006/11/12/books/review/Windolf.t.html
## 24:                                                                   http://www.nytimes.com/2008/11/05/books/05masl.html
## 25:                                                          http://www.nytimes.com/2008/11/23/books/review/Taylor-t.html
## 26:                                                                 http://www.nytimes.com/2008/01/21/books/21maslin.html
## 27:                                                        http://www.nytimes.com/2008/03/02/books/review/Campbell-t.html
## 28:                                                                   http://www.nytimes.com/2006/10/23/books/23masl.html
## 29:                                         http://www.nytimes.com/2014/06/08/books/review/stephen-kings-mr-mercedes.html
## 30:                                                            http://www.nytimes.com/1981/05/10/books/scare-tactics.html
## 31:                                    http://www.nytimes.com/1981/08/14/books/books-of-the-times-books-of-the-times.html
## 32:                                                http://www.nytimes.com/1982/08/11/books/books-of-the-times-074639.html
## 33:                                                  http://www.nytimes.com/1982/08/29/books/horror-writer-s-holiday.html
## 34:                                                http://www.nytimes.com/1983/04/03/books/the-other-woman-was-a-car.html
## 35:                                                http://www.nytimes.com/1983/04/12/books/books-of-the-times-093019.html
## 36:                                                http://www.nytimes.com/1983/10/21/books/books-of-the-times-243538.html
## 37:                                        http://www.nytimes.com/1985/06/09/books/don-t-turn-your-back-on-this-book.html
## 38:                                             http://www.nytimes.com/1987/02/22/books/what-the-wicked-magician-did.html
## 39:                                       http://www.nytimes.com/1987/05/31/books/summer-reading-sheldon-gets-the-ax.html
## 40:                                                http://www.nytimes.com/1987/06/08/books/books-of-the-times-301987.html
## 41:                                                http://www.nytimes.com/1987/11/05/books/books-of-the-times-950387.html
## 42:                                    http://www.nytimes.com/1987/12/20/books/not-with-a-bang-but-an-eeeooooarrrhmm.html
## 43:                    http://www.nytimes.com/1989/10/23/books/books-of-the-times-from-stephen-king-a-writer-s-demon.html
## 44:                                                http://www.nytimes.com/1989/10/29/books/his-alter-ego-is-a-killer.html
## 45:                                              http://www.nytimes.com/1991/09/29/books/avaunt-thee-recreant-cyborg.html
## 46:                       http://www.nytimes.com/1991/10/03/books/books-of-the-times-turning-favors-into-catastrophe.html
## 47:               http://www.nytimes.com/1994/10/06/books/books-of-the-times-lack-of-sleep-the-least-of-his-problems.html
## 48:                   http://www.nytimes.com/1995/06/26/books/book-review-a-punch-in-the-nose-then-a-new-life-begins.html
## 49:                       http://www.nytimes.com/1998/09/21/books/books-of-the-times-death-terror-and-writer-s-block.html
## 50:           http://www.nytimes.com/1999/04/15/books/books-of-the-times-a-modern-fairy-tale-of-the-dark-north-woods.html
## 51:                                            http://www.nytimes.com/1999/05/16/books/books-in-brief-fiction-583618.html
## 52:                   http://www.nytimes.com/2000/10/05/books/books-of-the-times-how-to-write-if-you-re-stephen-king.html
## 53:                                                                http://www.nytimes.com/2000/10/08/books/making-it.html
## 54:    http://www.nytimes.com/2001/03/15/books/books-of-the-times-a-fateful-step-off-a-curb-and-into-alien-territory.html
## 55:                                               http://www.nytimes.com/2001/04/15/books/weasel-from-another-planet.html
## 56:        http://www.nytimes.com/2002/09/23/books/books-of-the-times-cruising-the-dark-side-forget-about-seat-belts.html
## 57:                                             http://www.nytimes.com/2002/09/29/books/not-your-father-s-roadmaster.html
## 58:                                            http://www.nytimes.com/2004/06/20/books/books-in-brief-fiction-937851.html
## 59:                                                                   http://www.nytimes.com/2006/01/23/books/23masl.html
## 60:                                                         http://www.nytimes.com/2006/02/05/books/review/05itzkoff.html
## 61:                                     http://www.nytimes.com/2015/05/31/books/review/stephen-kings-finders-keepers.html
## 62:                                        http://www.nytimes.com/2016/06/12/books/review/stephen-kings-end-of-watch.html
## 63:                                            https://www.nytimes.com/2018/05/22/books/review/outsider-stephen-king.html
## 64:                                           https://www.nytimes.com/2018/10/26/books/review/stephen-king-elevation.html
## 65:                                           https://www.nytimes.com/2019/09/08/books/review-institute-stephen-king.html
## 66:                                       https://www.nytimes.com/2019/09/10/books/review/stephen-king-the-institute.html
##                                                                                                                       url
##     publication_dt                    byline
##             <char>                    <char>
##  1:     2011-11-13              ERROL MORRIS
##  2:     2011-10-31              JANET MASLIN
##  3:     2004-01-04            ANDREW O'HEHIR
##  4:     1993-10-24       RICHARD E. NICHOLLS
##  5:     2001-11-04   MARY ELIZABETH WILLIAMS
##  6:     1990-05-13              ROBERT KIELY
##  7:     1990-09-02              ANDY SOLOMON
##  8:     1991-10-20                          
##  9:     1992-06-29 CHRISTOPHER LEHMANN-HAUPT
## 10:     2002-04-14               WALTER KIRN
## 11:     1986-08-21 CHRISTOPHER LEHMANN-HAUPT
## 12:     2010-11-28         TERRENCE RAFFERTY
## 13:     1998-09-27         DANIEL MENDELSOHN
## 14:     2002-03-18              JANET MASLIN
## 15:     1995-07-02       RICHARD E. NICHOLLS
## 16:     2013-09-16              JANET MASLIN
## 17:     2013-09-22           MARGARET ATWOOD
## 18:     2013-06-23               WALTER KIRN
## 19:     2009-11-08              JAMES PARKER
## 20:     2009-11-12              JANET MASLIN
## 21:     2014-11-14              JANET MASLIN
## 22:     2014-11-23         DANIELLE TRUSSONI
## 23:     2006-11-12               JIM WINDOLF
## 24:     2008-11-05              JANET MASLIN
## 25:     2008-11-23            CHARLES TAYLOR
## 26:     2008-01-21              JANET MASLIN
## 27:     2008-03-02            JAMES CAMPBELL
## 28:     2006-10-23              JANET MASLIN
## 29:     2014-06-08              MEGAN ABBOTT
## 30:     1981-05-10             MICHELE SLUNG
## 31:     1981-08-14                          
## 32:     1982-08-11                          
## 33:     1982-08-29               ALAN CHEUSE
## 34:     1983-04-03        PHILLIPE VAN RJNDT
## 35:     1983-04-12                          
## 36:     1983-10-21                          
## 37:     1985-06-09             SUSAN BOLOTIN
## 38:     1987-02-22            BARBARA TRITEL
## 39:     1987-05-31           JOHN KATZENBACH
## 40:     1987-06-08                          
## 41:     1987-11-05                          
## 42:     1987-12-20             NINA AUERBACH
## 43:     1989-10-23                          
## 44:     1989-10-29              GEORGE STADE
## 45:     1991-09-29       RICHARD E. NICHOLLS
## 46:     1991-10-03                          
## 47:     1994-10-06                          
## 48:     1995-06-26                          
## 49:     1998-09-21                          
## 50:     1999-04-15                          
## 51:     1999-05-16              ANDREW ESSEX
## 52:     2000-10-05              JANET MASLIN
## 53:     2000-10-08           FREDERICK BUSCH
## 54:     2001-03-15              JANET MASLIN
## 55:     2001-04-15            COLIN HARRISON
## 56:     2002-09-23              JANET MASLIN
## 57:     2002-09-29              LAURA MILLER
## 58:     2004-06-20               BEN SISARIO
## 59:     2006-01-23              JANET MASLIN
## 60:     2006-02-05              DAVE ITZKOFF
## 61:     2015-05-31             LAURA LIPPMAN
## 62:     2016-06-12               DENISE MINA
## 63:     2018-05-22            VICTOR LAVALLE
## 64:     2018-10-26              GILBERT CRUZ
## 65:     2019-09-08             DWIGHT GARNER
## 66:     2019-09-10              LAURA MILLER
##     publication_dt                    byline
##                                     book_title  book_author
##                                         <char>       <char>
##  1:                                   11/22/63 Stephen King
##  2:                                   11/22/63 Stephen King
##  3:                        Wolves of the Calla Stephen King
##  4:                 Nightmares and Dreamscapes Stephen King
##  5:                                Black House Stephen King
##  6:                                  The Stand Stephen King
##  7:                         Four Past Midnight Stephen King
##  8:                             Needful Things Stephen King
##  9:                              Gerald's Game Stephen King
## 10:      Everything's Eventual : 14 Dark Tales Stephen King
## 11:                                         It Stephen King
## 12:                        Full Dark, No Stars Stephen King
## 13:                               Bag of Bones Stephen King
## 14:      Everything's Eventual : 14 Dark Tales Stephen King
## 15:                                Rose Madder Stephen King
## 16:                               Doctor Sleep Stephen King
## 17:                               Doctor Sleep Stephen King
## 18:                                    Joyland Stephen King
## 19:                             Under the Dome Stephen King
## 20:                             Under the Dome Stephen King
## 21:                                    Revival Stephen King
## 22:                                    Revival Stephen King
## 23:                              Lisey's Story Stephen King
## 24:                          Just After Sunset Stephen King
## 25:                          Just After Sunset Stephen King
## 26:                                   Duma Key Stephen King
## 27:                                   Duma Key Stephen King
## 28:                              Lisey's Story Stephen King
## 29:                               Mr. Mercedes Stephen King
## 30:               Stephen King's Danse Macabre Stephen King
## 31:                                       Cujo Stephen King
## 32:                          Different Seasons Stephen King
## 33:                          Different Seasons Stephen King
## 34:                                  Christine Stephen King
## 35:                                  Christine Stephen King
## 36:                               Pet Sematary Stephen King
## 37:                              Skeleton Crew Stephen King
## 38:                     The Eyes of the Dragon Stephen King
## 39:                                     Misery Stephen King
## 40:                                     Misery Stephen King
## 41:                          The Tommyknockers Stephen King
## 42:                          The Tommyknockers Stephen King
## 43:                              The Dark Half Stephen King
## 44:                              The Dark Half Stephen King
## 45:   The Waste Lands: The Dark Tower Book III Stephen King
## 46: Needful Things: The Last Castle Rock Story Stephen King
## 47:          Insomnia,Stephen King Library Ed. Stephen King
## 48:                                Rose Madder Stephen King
## 49:                               Bag of Bones Stephen King
## 50:    The Girl Who Loved Tom Gordon : A Novel Stephen King
## 51:    The Girl Who Loved Tom Gordon : A Novel Stephen King
## 52:         On Writing:  a Memoir of the Craft Stephen King
## 53:         On Writing:  a Memoir of the Craft Stephen King
## 54:                               Dreamcatcher Stephen King
## 55:                               Dreamcatcher Stephen King
## 56:                             From a Buick 8 Stephen King
## 57:                             From a Buick 8 Stephen King
## 58:                          The Dark Tower VI Stephen King
## 59:                                       Cell Stephen King
## 60:                                       Cell Stephen King
## 61:                            Finders Keepers Stephen King
## 62:                               End of Watch Stephen King
## 63:                               The Outsider Stephen King
## 64:                                  Elevation Stephen King
## 65:                              The Institute Stephen King
## 66:                              The Institute Stephen King
##                                     book_title  book_author
##                                                                                                                                                                                 summary
##                                                                                                                                                                                  <char>
##  1:                                                                                                                    Stephen King’s time traveler tries to undo some painful history.
##  2:                                             Stephen King’s latest novel, “11/22/63,” tells of a schoolteacher who travels back to 1958 to alter history, and falls in love as well.
##  3:                                                                                                                                                                                    
##  4:                                                                                                                                                                                    
##  5:                                                                                                                                                                                    
##  6:                                                                                                                                                                                    
##  7:                                                                                                                                                                                    
##  8:                                                                                                                                                                                    
##  9:                                                                                                                                                                                    
## 10:                                                                                                                                                                                    
## 11:                                                                                                                                                                                    
## 12:                                                                                                                                                                                    
## 13:                                                                                                                                                                                    
## 14:                                                                                                                                                                                    
## 15:                                                                                                                                                                                    
## 16:                                                                                                                    In “Doctor Sleep” Stephen King offers a sequel to “The Shining.”
## 17:                                               “Doctor Sleep” picks up the story of Danny, the little boy with psycho-intuitive powers from Stephen King’s 1977 novel “The Shining.”
## 18:                                                                                           Stephen King’s lovelorn narrator takes a summer job at a haunted Southern amusement park.
## 19: When an enormous transparent dome settles over a small town in Maine in Stephen King’s new novel, it’s just fine with Big Jim, the local tyrant-in-waiting, and his pet goon squad.
## 20:                                                                           “Under the Dome” gravely threatens Stephen King’s status as a mere chart-busting pop cultural phenomenon.
## 21:                                    In Stephen King’s “Revival,” a boy is befriended by a charismatic minister with whom he will reconnect in eerie and unsettling ways as an adult.
## 22:                                                 Two men are locked in a battle of wills in Stephen King&#8217;s novel of fanaticism and what might exist on the other side of life.
## 23:                                                                  When Stephen King really wants to put a scare into you, he brings on his most fearsome monster of all, the writer.
## 24:                                                               Everyday situations became open portals to fantasy and horror in Stephen King’s succinct, fast-moving new collection.
## 25:                                                                         A new short-story collection takes Stephen King back to the form that gave him his seat-of-the-pants start.
## 26:                   Stephen King’s use of horror is not what it used to be. It may still be the impetus for his stories, but it is no longer the foremost reason they’re interesting.
## 27:                                                                         In Stephen King’s new novel, a man recuperating in the Florida Keys begins to paint, with sinister results.
## 28:                                            In his new book, Stephen King delivers his version of Joycean wordplay, idiosyncrasy, voluptuousness and stubborn, obsessive chronology.
## 29:                                                                                                  With one eye on Philip Marlowe, Stephen King takes a crack at the detective novel.
## 30:                                                                                                                                                                                    
## 31:                                                                                                                                                                                    
## 32:                                                                                                                                                                                    
## 33:                                                                                                                                                                                    
## 34:                                                                                                                                                                                    
## 35:                                                                                                                                                                                    
## 36:                                                                                                                                                                                    
## 37:                                                                                                                                                                                    
## 38:                                                                                                                                                                                    
## 39:                                                                                                                                                                                    
## 40:                                                                                                                                                                                    
## 41:                                                                                                                                                                                    
## 42:                                                                                                                                                                                    
## 43:                                                                                                                                                                                    
## 44:                                                                                                                                                                                    
## 45:                                                                                                                                                                                    
## 46:                                                                                                                                                                                    
## 47:                                                                                                                                                                                    
## 48:                                                                                                                                                                                    
## 49:                                                                                                                                                                                    
## 50:                                                                                                                                                                                    
## 51:                                                                                                                                                                                    
## 52:                                                                                                                                                                                    
## 53:                                                                                                                                                                                    
## 54:                                                                                                                                                                                    
## 55:                                                                                                                                                                                    
## 56:                                                                                                                                                                                    
## 57:                                                                                                                                                                                    
## 58:                                                                                                                                                                                    
## 59:                                                                                                                                                                                    
## 60:                                                                                                                                                                                    
## 61:                                                       Laura Lippman reviews Stephen King’s “Finders Keepers,” the second entry in a planned trilogy that began with “Mr. Mercedes.”
## 62:                                                                         A retired police detective sees the return of his nemesis in this suspense story with a supernatural twist.
## 63:                                                              “The Outsider” starts out as a routine police procedural but before long transforms into something much more sinister.
## 64:                                          King’s slim new novel, “Elevation,” returns us to Castle Rock, where prejudice drives a plot that blends the fantastical with the mundane.
## 65:                               In his latest, King tells the story of an institution where children with special powers are cultivated — but that’s just where the nightmare begins.
## 66:                                                  The terror doesn’t come from ghosts or fiends or clowns — it’s ordinary people, folks just like you and me, who are the evil ones.
##                                                                                                                                                                                 summary
##                                     uuid
##                                   <char>
##  1: 00000000-0000-0000-0000-000000000000
##  2: 00000000-0000-0000-0000-000000000000
##  3: 00000000-0000-0000-0000-000000000000
##  4: 00000000-0000-0000-0000-000000000000
##  5: 00000000-0000-0000-0000-000000000000
##  6: 00000000-0000-0000-0000-000000000000
##  7: 00000000-0000-0000-0000-000000000000
##  8: 00000000-0000-0000-0000-000000000000
##  9: 00000000-0000-0000-0000-000000000000
## 10: 00000000-0000-0000-0000-000000000000
## 11: 00000000-0000-0000-0000-000000000000
## 12: 00000000-0000-0000-0000-000000000000
## 13: 00000000-0000-0000-0000-000000000000
## 14: 00000000-0000-0000-0000-000000000000
## 15: 00000000-0000-0000-0000-000000000000
## 16: 00000000-0000-0000-0000-000000000000
## 17: 00000000-0000-0000-0000-000000000000
## 18: 00000000-0000-0000-0000-000000000000
## 19: 00000000-0000-0000-0000-000000000000
## 20: 00000000-0000-0000-0000-000000000000
## 21: 00000000-0000-0000-0000-000000000000
## 22: 00000000-0000-0000-0000-000000000000
## 23: 00000000-0000-0000-0000-000000000000
## 24: 00000000-0000-0000-0000-000000000000
## 25: 00000000-0000-0000-0000-000000000000
## 26: 00000000-0000-0000-0000-000000000000
## 27: 00000000-0000-0000-0000-000000000000
## 28: 00000000-0000-0000-0000-000000000000
## 29: 00000000-0000-0000-0000-000000000000
## 30: 00000000-0000-0000-0000-000000000000
## 31: 00000000-0000-0000-0000-000000000000
## 32: 00000000-0000-0000-0000-000000000000
## 33: 00000000-0000-0000-0000-000000000000
## 34: 00000000-0000-0000-0000-000000000000
## 35: 00000000-0000-0000-0000-000000000000
## 36: 00000000-0000-0000-0000-000000000000
## 37: 00000000-0000-0000-0000-000000000000
## 38: 00000000-0000-0000-0000-000000000000
## 39: 00000000-0000-0000-0000-000000000000
## 40: 00000000-0000-0000-0000-000000000000
## 41: 00000000-0000-0000-0000-000000000000
## 42: 00000000-0000-0000-0000-000000000000
## 43: 00000000-0000-0000-0000-000000000000
## 44: 00000000-0000-0000-0000-000000000000
## 45: 00000000-0000-0000-0000-000000000000
## 46: 00000000-0000-0000-0000-000000000000
## 47: 00000000-0000-0000-0000-000000000000
## 48: 00000000-0000-0000-0000-000000000000
## 49: 00000000-0000-0000-0000-000000000000
## 50: 00000000-0000-0000-0000-000000000000
## 51: 00000000-0000-0000-0000-000000000000
## 52: 00000000-0000-0000-0000-000000000000
## 53: 00000000-0000-0000-0000-000000000000
## 54: 00000000-0000-0000-0000-000000000000
## 55: 00000000-0000-0000-0000-000000000000
## 56: 00000000-0000-0000-0000-000000000000
## 57: 00000000-0000-0000-0000-000000000000
## 58: 00000000-0000-0000-0000-000000000000
## 59: 00000000-0000-0000-0000-000000000000
## 60: 00000000-0000-0000-0000-000000000000
## 61: 00000000-0000-0000-0000-000000000000
## 62: 00000000-0000-0000-0000-000000000000
## 63: 00000000-0000-0000-0000-000000000000
## 64: 00000000-0000-0000-0000-000000000000
## 65: 00000000-0000-0000-0000-000000000000
## 66: 00000000-0000-0000-0000-000000000000
##                                     uuid
##                                                 uri
##                                              <char>
##  1: nyt://book/00000000-0000-0000-0000-000000000000
##  2: nyt://book/00000000-0000-0000-0000-000000000000
##  3: nyt://book/00000000-0000-0000-0000-000000000000
##  4: nyt://book/00000000-0000-0000-0000-000000000000
##  5: nyt://book/00000000-0000-0000-0000-000000000000
##  6: nyt://book/00000000-0000-0000-0000-000000000000
##  7: nyt://book/00000000-0000-0000-0000-000000000000
##  8: nyt://book/00000000-0000-0000-0000-000000000000
##  9: nyt://book/00000000-0000-0000-0000-000000000000
## 10: nyt://book/00000000-0000-0000-0000-000000000000
## 11: nyt://book/00000000-0000-0000-0000-000000000000
## 12: nyt://book/00000000-0000-0000-0000-000000000000
## 13: nyt://book/00000000-0000-0000-0000-000000000000
## 14: nyt://book/00000000-0000-0000-0000-000000000000
## 15: nyt://book/00000000-0000-0000-0000-000000000000
## 16: nyt://book/00000000-0000-0000-0000-000000000000
## 17: nyt://book/00000000-0000-0000-0000-000000000000
## 18: nyt://book/00000000-0000-0000-0000-000000000000
## 19: nyt://book/00000000-0000-0000-0000-000000000000
## 20: nyt://book/00000000-0000-0000-0000-000000000000
## 21: nyt://book/00000000-0000-0000-0000-000000000000
## 22: nyt://book/00000000-0000-0000-0000-000000000000
## 23: nyt://book/00000000-0000-0000-0000-000000000000
## 24: nyt://book/00000000-0000-0000-0000-000000000000
## 25: nyt://book/00000000-0000-0000-0000-000000000000
## 26: nyt://book/00000000-0000-0000-0000-000000000000
## 27: nyt://book/00000000-0000-0000-0000-000000000000
## 28: nyt://book/00000000-0000-0000-0000-000000000000
## 29: nyt://book/00000000-0000-0000-0000-000000000000
## 30: nyt://book/00000000-0000-0000-0000-000000000000
## 31: nyt://book/00000000-0000-0000-0000-000000000000
## 32: nyt://book/00000000-0000-0000-0000-000000000000
## 33: nyt://book/00000000-0000-0000-0000-000000000000
## 34: nyt://book/00000000-0000-0000-0000-000000000000
## 35: nyt://book/00000000-0000-0000-0000-000000000000
## 36: nyt://book/00000000-0000-0000-0000-000000000000
## 37: nyt://book/00000000-0000-0000-0000-000000000000
## 38: nyt://book/00000000-0000-0000-0000-000000000000
## 39: nyt://book/00000000-0000-0000-0000-000000000000
## 40: nyt://book/00000000-0000-0000-0000-000000000000
## 41: nyt://book/00000000-0000-0000-0000-000000000000
## 42: nyt://book/00000000-0000-0000-0000-000000000000
## 43: nyt://book/00000000-0000-0000-0000-000000000000
## 44: nyt://book/00000000-0000-0000-0000-000000000000
## 45: nyt://book/00000000-0000-0000-0000-000000000000
## 46: nyt://book/00000000-0000-0000-0000-000000000000
## 47: nyt://book/00000000-0000-0000-0000-000000000000
## 48: nyt://book/00000000-0000-0000-0000-000000000000
## 49: nyt://book/00000000-0000-0000-0000-000000000000
## 50: nyt://book/00000000-0000-0000-0000-000000000000
## 51: nyt://book/00000000-0000-0000-0000-000000000000
## 52: nyt://book/00000000-0000-0000-0000-000000000000
## 53: nyt://book/00000000-0000-0000-0000-000000000000
## 54: nyt://book/00000000-0000-0000-0000-000000000000
## 55: nyt://book/00000000-0000-0000-0000-000000000000
## 56: nyt://book/00000000-0000-0000-0000-000000000000
## 57: nyt://book/00000000-0000-0000-0000-000000000000
## 58: nyt://book/00000000-0000-0000-0000-000000000000
## 59: nyt://book/00000000-0000-0000-0000-000000000000
## 60: nyt://book/00000000-0000-0000-0000-000000000000
## 61: nyt://book/00000000-0000-0000-0000-000000000000
## 62: nyt://book/00000000-0000-0000-0000-000000000000
## 63: nyt://book/00000000-0000-0000-0000-000000000000
## 64: nyt://book/00000000-0000-0000-0000-000000000000
## 65: nyt://book/00000000-0000-0000-0000-000000000000
## 66: nyt://book/00000000-0000-0000-0000-000000000000
##                                                 uri
##                                                                                      isbn13
##                                                                                      <list>
##  1: 9780307951434,9780606351461,9781442344280,9781442344303,9781442391635,9781444727326,...
##  2: 9780307951434,9780606351461,9781442344280,9781442344303,9781442391635,9781444727326,...
##  3:                                                                           9781848941137
##  4:                                                                           9781441615299
##  5:                                                                           9780375504396
##  6:                                                                           9781848940833
##  7:                                                                           9780816151776
##  8:                                                                           9781598877427
##  9:                                                                           9780670846504
## 10:                                                                           9781439568200
## 11:                                                                           9780451169518
## 12: 9781439192566,9781439192597,9781439192603,9781441677112,9781442335769,9781444712582,...
## 13:                                                                           9780671026073
## 14:                                                                           9781416537816
## 15:                                                                           9781568952611
## 16:                                                                           9781451698855
## 17:                                                                           9781451698855
## 18:                                                                           9781781162644
## 19:                                                                           9781476735474
## 20:                                                                           9781476735474
## 21:     9781410473837,9781442372764,9781442372788,9781476770383,9781476770390,9781476770406
## 22:     9781410473837,9781442372764,9781442372788,9781476770383,9781476770390,9781476770406
## 23:                                                                           9781416523352
## 24:                                                                           9781416586654
## 25:                                                                           9781416586654
## 26:                                                                           9781416552963
## 27:                                                                           9781416552963
## 28:                                                                           9781416523352
## 29: 9781410469007,9781442369788,9781442371347,9781442395404,9781476754451,9781476754468,...
## 30:                                                                           9780896960763
## 31:                                                                           9780670451937
## 32:                                                                           9780670272662
## 33:                                                                           9780670272662
## 34:                                                                           9780670220267
## 35:                                                                           9780670220267
## 36:                                                                           9780385182447
## 37:                                                                                  [NULL]
## 38:                                                                                  [NULL]
## 39:                                                                           9780670813643
## 40:                                                                           9780670813643
## 41:                                                                           9780399133145
## 42:                                                                           9780399133145
## 43:                                                                                  [NULL]
## 44:                                                                                  [NULL]
## 45:                                                                           9780452267404
## 46:                                                                           9780670839537
## 47:                                                                           9780670855032
## 48:                                                                           9780670858699
## 49:                                                                           9780684853505
## 50:                                                                           9780684867625
## 51:                                                                           9780684867625
## 52: 9780606222549,9780606231862,9780671024253,9780684853529,9780743204361,9780743211536,...
## 53: 9780606222549,9780606231862,9780671024253,9780684853529,9780743204361,9780743211536,...
## 54:                                                                           9780743211383
## 55:                                                                           9780743211383
## 56:                                                                           9780743211376
## 57:                                                                           9780743211376
## 58:                                                                           9781880418598
## 59:                                                                           9780743292337
## 60:                                                                           9780743292337
## 61:     9781410479501,9781442384347,9781501100079,9781501100123,9781501100130,9781594138522
## 62:                   9781410489906,9781501129742,9781501134142,9781501134159,9781508211358
## 63:                                                                           9781501180989
## 64:                                                                           9781982102319
## 65:                                                                           9781982110567
## 66:                                                                           9781982110567
##                                                                                      isbn13

Analysis

I wanted to see how many books Stephen King published by year, I used the format function to extract the year from the published dates and created a columns for the years. To tidy the data I created primary keys, in order to normalize the data and create a separate table with the book date published and year.

Book_SK <- rowid_to_column(Book_SK, "ID") #Primary key for the published date for each book
head(Book_SK)
##   ID
## 1  1
## 2  2
## 3  3
## 4  4
## 5  5
## 6  6
##                                                                                        url
## 1 http://www.nytimes.com/2011/11/13/books/review/11-22-63-by-stephen-king-book-review.html
## 2               http://www.nytimes.com/2011/10/31/books/stephen-kings-11-23-63-review.html
## 3 http://www.nytimes.com/2004/01/04/books/the-quest-for-the-north-central-positronics.html
## 4                     http://www.nytimes.com/1993/10/24/books/in-short-fiction-284093.html
## 5        http://www.nytimes.com/2001/11/04/books/books-in-brief-fiction-poetry-851302.html
## 6               http://www.nytimes.com/1990/05/13/books/armageddon-complete-and-uncut.html
##   publication_dt                  byline                 book_title
## 1     2011-11-13            ERROL MORRIS                   11/22/63
## 2     2011-10-31            JANET MASLIN                   11/22/63
## 3     2004-01-04          ANDREW O'HEHIR        Wolves of the Calla
## 4     1993-10-24     RICHARD E. NICHOLLS Nightmares and Dreamscapes
## 5     2001-11-04 MARY ELIZABETH WILLIAMS                Black House
## 6     1990-05-13            ROBERT KIELY                  The Stand
##    book_author
## 1 Stephen King
## 2 Stephen King
## 3 Stephen King
## 4 Stephen King
## 5 Stephen King
## 6 Stephen King
##                                                                                                                                   summary
## 1                                                                        Stephen King’s time traveler tries to undo some painful history.
## 2 Stephen King’s latest novel, “11/22/63,” tells of a schoolteacher who travels back to 1958 to alter history, and falls in love as well.
## 3                                                                                                                                        
## 4                                                                                                                                        
## 5                                                                                                                                        
## 6                                                                                                                                        
##                                   uuid
## 1 00000000-0000-0000-0000-000000000000
## 2 00000000-0000-0000-0000-000000000000
## 3 00000000-0000-0000-0000-000000000000
## 4 00000000-0000-0000-0000-000000000000
## 5 00000000-0000-0000-0000-000000000000
## 6 00000000-0000-0000-0000-000000000000
##                                               uri
## 1 nyt://book/00000000-0000-0000-0000-000000000000
## 2 nyt://book/00000000-0000-0000-0000-000000000000
## 3 nyt://book/00000000-0000-0000-0000-000000000000
## 4 nyt://book/00000000-0000-0000-0000-000000000000
## 5 nyt://book/00000000-0000-0000-0000-000000000000
## 6 nyt://book/00000000-0000-0000-0000-000000000000
##                                                                                                                                                                               isbn13
## 1 9780307951434, 9780606351461, 9781442344280, 9781442344303, 9781442391635, 9781444727326, 9781451627282, 9781451627299, 9781451627305, 9781451651645, 9781501120602, 9781594135590
## 2 9780307951434, 9780606351461, 9781442344280, 9781442344303, 9781442391635, 9781444727326, 9781451627282, 9781451627299, 9781451627305, 9781451651645, 9781501120602, 9781594135590
## 3                                                                                                                                                                      9781848941137
## 4                                                                                                                                                                      9781441615299
## 5                                                                                                                                                                      9780375504396
## 6                                                                                                                                                                      9781848940833
Yr_pub<-subset(Book_SK, select = c(ID, publication_dt))
Yr_pub$year<-format(as.Date(Yr_pub$publication_dt, format = "%Y-%m-%d"), "%Y")
head(Yr_pub)
##   ID publication_dt year
## 1  1     2011-11-13 2011
## 2  2     2011-10-31 2011
## 3  3     2004-01-04 2004
## 4  4     1993-10-24 1993
## 5  5     2001-11-04 2001
## 6  6     1990-05-13 1990

Bar graph of with the amount of books Stephen King published each year.

ggplot(Yr_pub, aes(x=year), stat='count')+
  geom_bar()

Year with the max counts of books

Yr_pub%>% group_by(year)%>% summarise(count=n())%>%
  slice(which.max(count))#grouped by year to aggregate the occurrences of the years and used the which max to find the year with the max published books, the slice function was used to select the row with the max value.
## # A tibble: 1 × 2
##   year  count
##   <chr> <int>
## 1 1987      5

Conclusion

I was able to access and load the api data from New York Times, and create a data frame the json file. By creating a variable into the environment of R I was able to hide my api key, and load the url with my api key hidden. In this assignment I learned how to create api keys and how to use them to load the data into R without having to download the data and upload it into R. Using the API data from NY times and R, I was able to find the year that Stephan King published the most books which was 1987 he published 5 books.