Introduction The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs 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 to an R dataframe.

Search the top stories list of articles and associated images by the sections

# Load library
library(jsonlite)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
articleUrl <- "http://api.nytimes.com/svc/search/v2/articlesearch.json?q=%s&sort=newest&api-key=82badbe8a6564c9cbf9c12f877fdffc9"

out <- fromJSON(articleUrl)
out
## $response
## $response$meta
## $response$meta$hits
## [1] 6125257
## 
## $response$meta$time
## [1] 349
## 
## $response$meta$offset
## [1] 0
## 
## 
## $response$docs
##                                                                                                              web_url
## 1           http://www.nytimes.com/aponline/2016/10/30/us/politics/ap-us-campaign-2016-october-surprises-glance.html
## 2                        http://www.nytimes.com/2016/10/31/us/politics/donald-trump-hillary-clinton-james-comey.html
## 3                                      http://www.nytimes.com/2016/10/31/us/politics/fbi-hillary-clinton-emails.html
## 4  http://www.nytimes.com/2016/10/31/nyregion/a-lost-snippet-of-film-history-found-in-a-home-movie-shot-in-1964.html
## 5                                   http://www.nytimes.com/aponline/2016/10/30/sports/football/ap-fbn-inactives.html
## 6         http://www.nytimes.com/2016/10/31/sports/basketball/knicks-derrick-rose-mike-conley-memphis-grizzlies.html
## 7                              http://www.nytimes.com/2016/10/31/us/politics/anthony-weiner-democratic-reaction.html
## 8                         http://www.nytimes.com/reuters/2016/10/30/business/30reuters-brazil-economy-meirelles.html
## 9                                           http://www.nytimes.com/aponline/2016/10/30/us/ap-us-film-box-office.html
## 10             http://www.nytimes.com/2016/10/30/opinion/on-clinton-emails-did-the-fbi-director-abuse-his-power.html
##                                                                                                                                                                                                                                                   snippet
## 1                                                                                                   U.S. presidential campaigns are never predictable, although the number of late-breaking, surprise developments in the 2016 campaign may set the mark.
## 2                                                                                           The campaigns battled over the director’s conduct and personal credibility — with only scant insight into the substance behind the new Clinton email inquiry.
## 3                                                  Many voters are puzzling over what to make of a case involving Hillary Clinton’s email server, a disgraced congressman, and a dispute among top law enforcement officials. Here’s what we know so far.
## 4                                                                                                              During a summer internship, an aspiring archivist stumbles on a recording of a World’s Fair installation created by Charles and Ray Eames.
## 5                                                                                                   The Green Bay Packers will play in Atlanta without star pass rusher Clay Matthews and wide receiver Randall Cobb, both because of hamstring injuries.
## 6                                                                                           The Knicks’ versatile attack on Saturday against the Grizzlies underscored that they need Rose to be more like the understated Mike Conley Jr. than an M.V.P.
## 7                                                                                                   In the campaign’s waning days, the disgraced congressman is at the center of the F.B.I.’s renewed interest in Hillary Clinton’s private email server.
## 8  Brazil must push ahead with reforms, including a proposed cap on government spending and an overhaul of social security rules, to restore long-term order to public finances in Latin America's biggest economy, according to the country's finance...
## 9                                                                                                                                                             Tom Hanks. Tom Cruise. Ben Affleck. None of them have been a match for Tyler Perry's Madea.
## 10                                                                                                                                                                 If the announcement influences the election, it could be a violation of the Hatch Act.
##                                                                                                                                                                                                                                                   lead_paragraph
## 1                                                                                                          U.S. presidential campaigns are never predictable, although the number of late-breaking, surprise developments in the 2016 campaign may set the mark.
## 2                                                                                                  The campaigns battled over the director’s conduct and personal credibility — with only scant insight into the substance behind the new Clinton email inquiry.
## 3                                                         Many voters are puzzling over what to make of a case involving Hillary Clinton’s email server, a disgraced congressman, and a dispute among top law enforcement officials. Here’s what we know so far.
## 4                                                                                                                     During a summer internship, an aspiring archivist stumbles on a recording of a World’s Fair installation created by Charles and Ray Eames.
## 5                                                                                                          The Green Bay Packers will play in Atlanta without star pass rusher Clay Matthews and wide receiver Randall Cobb, both because of hamstring injuries.
## 6                                                                                                  The Knicks’ versatile attack on Saturday against the Grizzlies underscored that they need Rose to be more like the understated Mike Conley Jr. than an M.V.P.
## 7                                                                                                          In the campaign’s waning days, the disgraced congressman is at the center of the F.B.I.’s renewed interest in Hillary Clinton’s private email server.
## 8  Brazil must push ahead with reforms, including a proposed cap on government spending and an overhaul of social security rules, to restore long-term order to public finances in Latin America's biggest economy, according to the country's finance minister.
## 9                                                                                                                                                                    Tom Hanks. Tom Cruise. Ben Affleck. None of them have been a match for Tyler Perry's Madea.
## 10                                                                                                                                                                        If the announcement influences the election, it could be a violation of the Hatch Act.
##    abstract print_page blog             source
## 1        NA         NA NULL                 AP
## 2        NA         NA NULL The New York Times
## 3        NA         NA NULL The New York Times
## 4        NA         NA NULL The New York Times
## 5        NA         NA NULL                 AP
## 6        NA         NA NULL The New York Times
## 7        NA         NA NULL The New York Times
## 8        NA         NA NULL            Reuters
## 9        NA         NA NULL                 AP
## 10       NA         NA NULL The New York Times
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  multimedia
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      NULL
## 2                    190, 600, 75, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-thumbWide.jpg, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-articleLarge.jpg, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-thumbStandard.jpg, 126, 330, 75, wide, xlarge, thumbnail, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-thumbWide.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-articleLarge.jpg, NA, NA, 330, NA, NA, NA, 75, NA, NA, images/2016/10/31/us/31CAMPAIGNweb1/31CAMPAIGNweb1-thumbStandard.jpg, NA, NA, 75, image, image, image
## 3                                                  190, 600, 75, images/2016/10/31/us/31QandA-web/31QandA-web-thumbWide.jpg, images/2016/10/31/us/31QandA-web/31QandA-web-articleLarge.jpg, images/2016/10/31/us/31QandA-web/31QandA-web-thumbStandard-v3.jpg, 126, 400, 75, wide, xlarge, thumbnail, images/2016/10/31/us/31QandA-web/31QandA-web-thumbWide.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/31/us/31QandA-web/31QandA-web-articleLarge.jpg, NA, NA, 400, NA, NA, NA, 75, NA, NA, images/2016/10/31/us/31QandA-web/31QandA-web-thumbStandard-v3.jpg, NA, NA, 75, image, image, image
## 4        190, 600, 75, images/2016/10/31/nyregion/31gracenotes/31gracenotes-thumbWide.jpg, images/2016/10/31/nyregion/31gracenotes/31gracenotes-articleLarge.jpg, images/2016/10/31/nyregion/31gracenotes/31gracenotes-thumbStandard.jpg, 126, 400, 75, wide, xlarge, thumbnail, images/2016/10/31/nyregion/31gracenotes/31gracenotes-thumbWide.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/31/nyregion/31gracenotes/31gracenotes-articleLarge.jpg, NA, NA, 400, NA, NA, NA, 75, NA, NA, images/2016/10/31/nyregion/31gracenotes/31gracenotes-thumbStandard.jpg, NA, NA, 75, image, image, image
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      NULL
## 6        190, 600, 75, images/2016/10/31/sports/31araton-web/31araton-web-thumbWide-v2.jpg, images/2016/10/31/sports/31araton-web/31araton-web-articleLarge.jpg, images/2016/10/31/sports/31araton-web/31araton-web-thumbStandard-v2.jpg, 126, 428, 75, wide, xlarge, thumbnail, images/2016/10/31/sports/31araton-web/31araton-web-thumbWide-v2.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/31/sports/31araton-web/31araton-web-articleLarge.jpg, NA, NA, 428, NA, NA, NA, 75, NA, NA, images/2016/10/31/sports/31araton-web/31araton-web-thumbStandard-v2.jpg, NA, NA, 75, image, image, image
## 7                                            190, 600, 75, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-thumbWide.jpg, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-articleLarge.jpg, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-thumbStandard.jpg, 126, 400, 75, wide, xlarge, thumbnail, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-thumbWide.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-articleLarge.jpg, NA, NA, 400, NA, NA, NA, 75, NA, NA, images/2016/10/30/us/31WEINERDEMS/31WEINERDEMS-thumbStandard.jpg, NA, NA, 75, image, image, image
## 8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      NULL
## 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      NULL
## 10 190, 600, 75, images/2016/10/30/opinion/30painter-img/30painter-img-thumbWide.jpg, images/2016/10/30/opinion/30painter-img/30painter-img-articleLarge.jpg, images/2016/10/30/opinion/30painter-img/30painter-img-thumbStandard.jpg, 126, 400, 75, wide, xlarge, thumbnail, images/2016/10/30/opinion/30painter-img/30painter-img-thumbWide.jpg, NA, NA, 126, NA, NA, 190, NA, NA, NA, 600, NA, NA, images/2016/10/30/opinion/30painter-img/30painter-img-articleLarge.jpg, NA, NA, 400, NA, NA, NA, 75, NA, NA, images/2016/10/30/opinion/30painter-img/30painter-img-thumbStandard.jpg, NA, NA, 75, image, image, image
##                                                               headline.main
## 1                     So Far, Sexting, Groping Is 2016's 'October Surprise'
## 2       Campaigns Shift Focus to F.B.I. Director in Sunday Show Appearances
## 3                          10 Questions (and Answers) About New Email Trove
## 4        A Lost Snippet of Film History, Found in a Home Movie Shot in 1964
## 5                     Packers Without Matthews, Cobb; Broncos Scratch Talib
## 6            A Knicks Opponent Offers Derrick Rose a Low-Profile Role Model
## 7                   For Democrats, Anthony Weiner Makes an Unwelcome Return
## 8  Brazil Finance Minister Says Spending, Retirement Reforms Crucial-Report
## 9                Perry's 'Madea' Stuns Hanks' 'Inferno' in Box Office Upset
## 10              On Clinton Emails, Did the F.B.I. Director Abuse His Power?
##                                                     headline.print_headline
## 1                     So Far, Sexting, Groping Is 2016's 'October Surprise'
## 2                                                                      <NA>
## 3                                                                      <NA>
## 4                                                                      <NA>
## 5                     Packers Without Matthews, Cobb; Broncos Scratch Talib
## 6                                                                      <NA>
## 7                                                                      <NA>
## 8  Brazil Finance Minister Says Spending, Retirement Reforms Crucial-Report
## 9                Perry's 'Madea' Stuns Hanks' 'Inferno' in Box Office Upset
## 10                                                                     <NA>
##    headline.content_kicker   headline.kicker
## 1                     <NA>              <NA>
## 2                     <NA>              <NA>
## 3                     <NA>              <NA>
## 4                     <NA>              <NA>
## 5                     <NA>              <NA>
## 6        On Pro Basketball On Pro Basketball
## 7                     <NA>              <NA>
## 8                     <NA>              <NA>
## 9                     <NA>              <NA>
## 10       Op-Ed Contributor Op-Ed Contributor
##                                                                                                                                                                                                                                                                                                                                 keywords
## 1                                                                                                                                                                                                                                                                                                                                   NULL
## 2                                                                                                                                                        1, 2, 3, 4, 5, N, N, N, N, N, subject, persons, persons, persons, persons, Presidential Election of 2016, Comey, James B, Clinton, Hillary Rodham, Pence, Mike, Trump, Donald J
## 3                                                                                                                            1, 2, 3, 4, 5, N, N, N, N, N, organizations, persons, persons, persons, subject, Federal Bureau of Investigation, Clinton, Hillary Rodham, Comey, James B, Weiner, Anthony D, Presidential Election of 2016
## 4                                                                                                                                                1, 2, 3, 4, 6, N, N, N, N, N, subject, subject, subject, creative_works, organizations, Movies, Archives and Records, World's Fair of 1964-65 (NYC), Think (Movie), New York University
## 5                                                                                                                                                                                                                                                                                                                                   NULL
## 6                                                                                                                                                         1, 2, 3, 4, 5, N, N, N, N, N, subject, organizations, organizations, persons, persons, Basketball, New York Knicks, Memphis Grizzlies, Rose, Derrick, Conley, Mike Jr (1987- )
## 7                                                                                                                                                                                     1, 2, 3, 4, N, N, N, N, subject, persons, persons, organizations, Presidential Election of 2016, Weiner, Anthony D, Abedin, Huma, Democratic Party
## 8                                                                                                                                                                                                                                                                                                                                   NULL
## 9                                                                                                                                                                                                                                                                                                                                   NULL
## 10 1, 2, 3, 4, 5, 6, 7, 8, N, N, N, N, N, N, N, N, subject, persons, persons, subject, subject, organizations, organizations, organizations, Presidential Election of 2016, Clinton, Hillary Rodham, Comey, James B, E-Mail, Classified Information and State Secrets, Federal Bureau of Investigation, House of Representatives, Senate
##                pub_date document_type news_desk  section_name
## 1  2016-10-30T18:12:47Z       article      <NA>          U.S.
## 2  2016-10-30T18:08:18Z       article  National          U.S.
## 3  2016-10-30T17:14:14Z       article  National          U.S.
## 4  2016-10-30T16:35:31Z       article     Metro N.Y. / Region
## 5  2016-10-30T16:12:51Z       article      <NA>        Sports
## 6  2016-10-30T16:10:07Z       article    Sports        Sports
## 7  2016-10-30T16:04:43Z       article  National          U.S.
## 8  2016-10-30T16:03:27Z       article      <NA>  Business Day
## 9  2016-10-30T15:45:50Z       article      <NA>          U.S.
## 10 2016-10-30T13:32:59Z       article      OpEd       Opinion
##    subsection_name
## 1         Politics
## 2         Politics
## 3         Politics
## 4             <NA>
## 5     Pro Football
## 6   Pro Basketball
## 7         Politics
## 8             <NA>
## 9             <NA>
## 10            <NA>
##                                                           byline.person
## 1                                                                  NULL
## 2                                       , reported, Alexander, 1, BURNS
## 3  Michael, Matt, S., NA, SCHMIDT, APUZZO, 1, 2, reported, reported, , 
## 4                                          , reported, James, 1, BARRON
## 5                                                                  NULL
## 6                                         , reported, Harvey, 1, ARATON
## 7      , , reported, reported, Maggie, Alexander, 1, 2, HABERMAN, BURNS
## 8                                                                  NULL
## 9                                                                  NULL
## 10                                  Richard, W., PAINTER, 1, reported, 
##                           byline.original  byline.organization
## 1                 By THE ASSOCIATED PRESS THE ASSOCIATED PRESS
## 2                      By ALEXANDER BURNS                 <NA>
## 3   By MICHAEL S. SCHMIDT and MATT APUZZO                 <NA>
## 4                         By JAMES BARRON                 <NA>
## 5                 By THE ASSOCIATED PRESS THE ASSOCIATED PRESS
## 6                        By HARVEY ARATON                 <NA>
## 7  By MAGGIE HABERMAN and ALEXANDER BURNS                 <NA>
## 8                              By REUTERS              REUTERS
## 9                 By THE ASSOCIATED PRESS THE ASSOCIATED PRESS
## 10                  By RICHARD W. PAINTER                 <NA>
##    type_of_material                      _id word_count slideshow_credits
## 1              News 5816382e7c459f606398c956        676                NA
## 2              News 5816371c7c459f606398c952       1010                NA
## 3              News 58162a697c459f606398c93f       1448                NA
## 4              News 5816215e7c459f606398c92a       1121                NA
## 5              News 58161c0a7c459f606398c921        700                NA
## 6              News 58161b687c459f606398c91f        925                NA
## 7              News 58161a227c459f606398c91e       1207                NA
## 8              News 581619de7c459f606398c91d        326                NA
## 9              News 581615b57c459f606398c919        657                NA
## 10            Op-Ed 5815f6917c459f606398c8f2        853                NA
## 
## 
## $status
## [1] "OK"
## 
## $copyright
## [1] "Copyright (c) 2013 The New York Times Company.  All Rights Reserved."
# Display column names in data frame
outDf <- data.frame(out[[1]]$docs)
variable.names(outDf)
##  [1] "web_url"           "snippet"           "lead_paragraph"   
##  [4] "abstract"          "print_page"        "blog"             
##  [7] "source"            "multimedia"        "headline"         
## [10] "keywords"          "pub_date"          "document_type"    
## [13] "news_desk"         "section_name"      "subsection_name"  
## [16] "byline"            "type_of_material"  "X_id"             
## [19] "word_count"        "slideshow_credits"
length(outDf)
## [1] 20
# Select subset of columns in data frame
outSub <- select(outDf, snippet, lead_paragraph, headline, pub_date, section_name)

# Identify the widest column
outWidth <- max(sapply(names(outSub), nchar))
format(outSub, width = outWidth, justify = "left")
##                                                                                                                                                                                                                                                   snippet
## 1  U.S. presidential campaigns are never predictable, although the number of late-breaking, surprise developments in the 2016 campaign may set the mark.                                                                                                 
## 2  The campaigns battled over the director’s conduct and personal credibility — with only scant insight into the substance behind the new Clinton email inquiry.                                                                                         
## 3  Many voters are puzzling over what to make of a case involving Hillary Clinton’s email server, a disgraced congressman, and a dispute among top law enforcement officials. Here’s what we know so far.                                                
## 4  During a summer internship, an aspiring archivist stumbles on a recording of a World’s Fair installation created by Charles and Ray Eames.                                                                                                            
## 5  The Green Bay Packers will play in Atlanta without star pass rusher Clay Matthews and wide receiver Randall Cobb, both because of hamstring injuries.                                                                                                 
## 6  The Knicks’ versatile attack on Saturday against the Grizzlies underscored that they need Rose to be more like the understated Mike Conley Jr. than an M.V.P.                                                                                         
## 7  In the campaign’s waning days, the disgraced congressman is at the center of the F.B.I.’s renewed interest in Hillary Clinton’s private email server.                                                                                                 
## 8  Brazil must push ahead with reforms, including a proposed cap on government spending and an overhaul of social security rules, to restore long-term order to public finances in Latin America's biggest economy, according to the country's finance...
## 9  Tom Hanks. Tom Cruise. Ben Affleck. None of them have been a match for Tyler Perry's Madea.                                                                                                                                                           
## 10 If the announcement influences the election, it could be a violation of the Hatch Act.                                                                                                                                                                
##                                                                                                                                                                                                                                                   lead_paragraph
## 1  U.S. presidential campaigns are never predictable, although the number of late-breaking, surprise developments in the 2016 campaign may set the mark.                                                                                                        
## 2  The campaigns battled over the director’s conduct and personal credibility — with only scant insight into the substance behind the new Clinton email inquiry.                                                                                                
## 3  Many voters are puzzling over what to make of a case involving Hillary Clinton’s email server, a disgraced congressman, and a dispute among top law enforcement officials. Here’s what we know so far.                                                       
## 4  During a summer internship, an aspiring archivist stumbles on a recording of a World’s Fair installation created by Charles and Ray Eames.                                                                                                                   
## 5  The Green Bay Packers will play in Atlanta without star pass rusher Clay Matthews and wide receiver Randall Cobb, both because of hamstring injuries.                                                                                                        
## 6  The Knicks’ versatile attack on Saturday against the Grizzlies underscored that they need Rose to be more like the understated Mike Conley Jr. than an M.V.P.                                                                                                
## 7  In the campaign’s waning days, the disgraced congressman is at the center of the F.B.I.’s renewed interest in Hillary Clinton’s private email server.                                                                                                        
## 8  Brazil must push ahead with reforms, including a proposed cap on government spending and an overhaul of social security rules, to restore long-term order to public finances in Latin America's biggest economy, according to the country's finance minister.
## 9  Tom Hanks. Tom Cruise. Ben Affleck. None of them have been a match for Tyler Perry's Madea.                                                                                                                                                                  
## 10 If the announcement influences the election, it could be a violation of the Hatch Act.                                                                                                                                                                       
##                                                               headline.main
## 1  So Far, Sexting, Groping Is 2016's 'October Surprise'                   
## 2  Campaigns Shift Focus to F.B.I. Director in Sunday Show Appearances     
## 3  10 Questions (and Answers) About New Email Trove                        
## 4  A Lost Snippet of Film History, Found in a Home Movie Shot in 1964      
## 5  Packers Without Matthews, Cobb; Broncos Scratch Talib                   
## 6  A Knicks Opponent Offers Derrick Rose a Low-Profile Role Model          
## 7  For Democrats, Anthony Weiner Makes an Unwelcome Return                 
## 8  Brazil Finance Minister Says Spending, Retirement Reforms Crucial-Report
## 9  Perry's 'Madea' Stuns Hanks' 'Inferno' in Box Office Upset              
## 10 On Clinton Emails, Did the F.B.I. Director Abuse His Power?             
##                                                     headline.print_headline
## 1  So Far, Sexting, Groping Is 2016's 'October Surprise'                   
## 2  NA                                                                      
## 3  NA                                                                      
## 4  NA                                                                      
## 5  Packers Without Matthews, Cobb; Broncos Scratch Talib                   
## 6  NA                                                                      
## 7  NA                                                                      
## 8  Brazil Finance Minister Says Spending, Retirement Reforms Crucial-Report
## 9  Perry's 'Madea' Stuns Hanks' 'Inferno' in Box Office Upset              
## 10 NA                                                                      
##    headline.content_kicker   headline.kicker             pub_date
## 1        NA                NA                2016-10-30T18:12:47Z
## 2        NA                NA                2016-10-30T18:08:18Z
## 3        NA                NA                2016-10-30T17:14:14Z
## 4        NA                NA                2016-10-30T16:35:31Z
## 5        NA                NA                2016-10-30T16:12:51Z
## 6        On Pro Basketball On Pro Basketball 2016-10-30T16:10:07Z
## 7        NA                NA                2016-10-30T16:04:43Z
## 8        NA                NA                2016-10-30T16:03:27Z
## 9        NA                NA                2016-10-30T15:45:50Z
## 10       Op-Ed Contributor Op-Ed Contributor 2016-10-30T13:32:59Z
##      section_name
## 1  U.S.          
## 2  U.S.          
## 3  U.S.          
## 4  N.Y. / Region 
## 5  Sports        
## 6  Sports        
## 7  U.S.          
## 8  Business Day  
## 9  U.S.          
## 10 Opinion