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.

library(httr)
library(jsonlite)
library(RCurl)
## Loading required package: bitops

I chose the geographic API.

1) Query I : With Country code “US”

APIkey <- "&api-key=23b48cef8cb5434b8efec48a494a9a62"
#url <- "http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?(query parameters)&api-key=your-API-key" (general form of query)
base_url <-getURL("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?country_code=US&api-key=23b48cef8cb5434b8efec48a494a9a62")
req <- fromJSON(base_url)
req <- data.frame(req)
head(req)
##   status
## 1     OK
## 2     OK
## 3     OK
## 4     OK
## 5     OK
## 6     OK
##                                                             copyright
## 1 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 2 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 3 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 4 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 5 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 6 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
##   num_results results.concept_id            results.concept_name
## 1          20              24012            Charlottesville (Va)
## 2          20              28132               Philadelphia (Pa)
## 3          20              28848 San Juan National Forest (Colo)
## 4          20              27356                Nantucket (Mass)
## 5          20              71052                   Yamhill (Ore)
## 6          20              27744                      Ohio River
##   results.geocode_id results.geoname_id             results.name
## 1               2840            4752031          Charlottesville
## 2                436            4560349             Philadelphia
## 3               7240            5437675 San Juan National Forest
## 4               1312            4944903                Nantucket
## 5               8680            5761959                  Yamhill
## 6               3916            4401696               Ohio River
##   results.latitude results.longitude results.elevation results.population
## 1         38.02931         -78.47668               142              34703
## 2         39.95233         -75.16379                12            1517550
## 3         37.69166        -107.80895              3472                 NA
## 4         41.28346         -70.09946                13              14775
## 5         45.34150        -123.18733                60               1024
## 6         36.98672         -89.13062                87                 NA
##   results.country_code results.country_name results.admin_code1
## 1                   US        United States                  VA
## 2                   US        United States                  PA
## 3                   US        United States                  CO
## 4                   US        United States                  MA
## 5                   US        United States                  OR
## 6                   US        United States                  MO
##   results.admin_code2 results.admin_code3 results.admin_code4
## 1                 540                  NA                  NA
## 2                 101                  NA                  NA
## 3                 111                  NA                  NA
## 4                 019                  NA                  NA
## 5                 071                  NA                  NA
## 6                 133                  NA                  NA
##   results.admin_name1     results.admin_name2 results.admin_name3
## 1            Virginia City of Charlottesville                  NA
## 2        Pennsylvania     Philadelphia County                  NA
## 3            Colorado         San Juan County                  NA
## 4       Massachusetts        Nantucket County                  NA
## 5              Oregon          Yamhill County                  NA
## 6            Missouri      Mississippi County                  NA
##   results.admin_name4 results.feature_class results.feature_code
## 1                  NA                     P                  PPL
## 2                  NA                     P                  PPL
## 3                  NA                     V                 FRST
## 4                  NA                     P                  PPL
## 5                  NA                     P                  PPL
## 6                  NA                     H                  STM
##   results.feature_code_name results.time_zone_id results.dst_offset
## 1           populated place     America/New_York                 -4
## 2           populated place     America/New_York                 -4
## 3                 forest(s)     America/Shiprock                 -6
## 4           populated place     America/New_York                 -4
## 5           populated place  America/Los_Angeles                 -7
## 6                    stream America/Indiana/Knox                 -5
##   results.gmt_offset  results.geocodes_created  results.geocodes_updated
## 1                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 2                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 3                 -7 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 4                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 5                 -8 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 6                 -6 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00

Query II : With admin_code = NY

APIkey <- "23b48cef8cb5434b8efec48a494a9a62"
base_url1 <-getURL("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?admin_code1=NY&api-key=23b48cef8cb5434b8efec48a494a9a62")
req1 <- fromJSON(base_url1)
req1 <- data.frame(req1)
head(req1)
##   status
## 1     OK
## 2     OK
## 3     OK
## 4     OK
## 5     OK
## 6     OK
##                                                             copyright
## 1 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 2 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 3 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 4 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 5 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 6 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
##   num_results results.concept_id    results.concept_name
## 1          20              25820 Huntington Station (NY)
## 2          20              27508       New Rochelle (NY)
## 3          20              25796            Hudson River
## 4          20              29604          Tarrytown (NY)
## 5          20              29260           Southold (NY)
## 6          20              29956           Valhalla (NY)
##   results.geocode_id results.geoname_id       results.name
## 1               5320            5121650 Huntington Station
## 2               2652            5128549       New Rochelle
## 3                564            5121521       Hudson River
## 4               3648            5140538          Tarrytown
## 5               4352            5139054           Southold
## 6               3652            5142090           Valhalla
##   results.latitude results.longitude results.elevation results.population
## 1         40.85343         -73.41151                66              30484
## 2         40.91149         -73.78235                26              72786
## 3         40.69677         -74.02820                NA                 NA
## 4         41.07621         -73.85875                37              11460
## 5         41.06482         -72.42620                 7               5554
## 6         41.07482         -73.77513                78               5463
##   results.country_code results.country_name results.admin_code1
## 1                   US        United States                  NY
## 2                   US        United States                  NY
## 3                   US        United States                  NY
## 4                   US        United States                  NY
## 5                   US        United States                  NY
## 6                   US        United States                  NY
##   results.admin_code2 results.admin_code3 results.admin_code4
## 1                 103                  NA                  NA
## 2                 119                  NA                  NA
## 3                 061                  NA                  NA
## 4                 119                  NA                  NA
## 5                 103                  NA                  NA
## 6                 119                  NA                  NA
##   results.admin_name1 results.admin_name2 results.admin_name3
## 1            New York      Suffolk County                  NA
## 2            New York  Westchester County                  NA
## 3            New York     New York County                  NA
## 4            New York  Westchester County                  NA
## 5            New York      Suffolk County                  NA
## 6            New York  Westchester County                  NA
##   results.admin_name4 results.feature_class results.feature_code
## 1                  NA                     P                  PPL
## 2                  NA                     P                  PPL
## 3                  NA                     H                  STM
## 4                  NA                     P                  PPL
## 5                  NA                     P                  PPL
## 6                  NA                     P                  PPL
##   results.feature_code_name results.time_zone_id results.dst_offset
## 1           populated place     America/New_York                 -4
## 2           populated place     America/New_York                 -4
## 3                    stream     America/New_York                 -4
## 4           populated place     America/New_York                 -4
## 5           populated place     America/New_York                 -4
## 6           populated place     America/New_York                 -4
##   results.gmt_offset  results.geocodes_created  results.geocodes_updated
## 1                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 2                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 3                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 4                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 5                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 6                 -5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00

Query III : With country_code = “US” and Population = 50000.

APIkey <- "23b48cef8cb5434b8efec48a494a9a62"
base_url2 <-getURL("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?feature_class=P&country_code=US&population=50000_&api-key=23b48cef8cb5434b8efec48a494a9a62")
req2 <- fromJSON(base_url2)
req2 <- data.frame(req2)
head(req2)
##   status
## 1     OK
## 2     OK
## 3     OK
## 4     OK
## 5     OK
## 6     OK
##                                                             copyright
## 1 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 2 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 3 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 4 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 5 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
## 6 Copyright (c) 2015 The New York Times Company. All Rights Reserved.
##   num_results results.concept_id results.concept_name results.geocode_id
## 1          20              24012 Charlottesville (Va)               2840
## 2          20              28132    Philadelphia (Pa)                436
## 3          20              27356     Nantucket (Mass)               1312
## 4          20              71052        Yamhill (Ore)               8680
## 5          20              23236        Bellport (NY)               5036
## 6          20              29164   Sleepy Hollow (NY)               4340
##   results.geoname_id    results.name results.latitude results.longitude
## 1            4752031 Charlottesville         38.02931         -78.47668
## 2            4560349    Philadelphia         39.95233         -75.16379
## 3            4944903       Nantucket         41.28346         -70.09946
## 4            5761959         Yamhill         45.34150        -123.18733
## 5            5108714        Bellport         40.75704         -72.93927
## 6            5138371   Sleepy Hollow         41.08565         -73.85847
##   results.elevation results.population results.country_code
## 1               142              34703                   US
## 2                12            1517550                   US
## 3                13              14775                   US
## 4                60               1024                   US
## 5                 8               2377                   US
## 6                27               9286                   US
##   results.country_name results.admin_code1 results.admin_code2
## 1        United States                  VA                 540
## 2        United States                  PA                 101
## 3        United States                  MA                 019
## 4        United States                  OR                 071
## 5        United States                  NY                 103
## 6        United States                  NY                 119
##   results.admin_code3 results.admin_code4 results.admin_name1
## 1                  NA                  NA            Virginia
## 2                  NA                  NA        Pennsylvania
## 3                  NA                  NA       Massachusetts
## 4                  NA                  NA              Oregon
## 5                  NA                  NA            New York
## 6                  NA                  NA            New York
##       results.admin_name2 results.admin_name3 results.admin_name4
## 1 City of Charlottesville                  NA                  NA
## 2     Philadelphia County                  NA                  NA
## 3        Nantucket County                  NA                  NA
## 4          Yamhill County                  NA                  NA
## 5          Suffolk County                  NA                  NA
## 6      Westchester County                  NA                  NA
##   results.feature_class results.feature_code results.feature_code_name
## 1                     P                  PPL           populated place
## 2                     P                  PPL           populated place
## 3                     P                  PPL           populated place
## 4                     P                  PPL           populated place
## 5                     P                  PPL           populated place
## 6                     P                  PPL           populated place
##   results.time_zone_id results.dst_offset results.gmt_offset
## 1     America/New_York                 -4                 -5
## 2     America/New_York                 -4                 -5
## 3     America/New_York                 -4                 -5
## 4  America/Los_Angeles                 -7                 -8
## 5     America/New_York                 -4                 -5
## 6     America/New_York                 -4                 -5
##    results.geocodes_created  results.geocodes_updated
## 1 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 2 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 3 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 4 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 5 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00
## 6 2013-02-25 15:10:12-05:00 2013-02-25 15:10:12-05:00