Giter Site home page Giter Site logo

nytimes's Introduction

nytimes

lifecycle

  • R functions for accessing New York Times’ APIs
  • Functionality currently extends to “article search”, “most popular”, and “Times newswire” APIs.

Authorizing API access

## replace x's with nytimes article search API key which
##    you can acquire by visiting the following URL:
##    https://developer.nytimes.com/signup
apikey <- paste0("NYTIMES_KEY=", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx")

## make path to .Renviron
file <- file.path(path.expand("~"), ".Renviron")

## save environment variable
cat(apikey, file = file, append = TRUE, fill = TRUE)

Using nytimes package

Install package

install.packages("devtools")
devtools::install_github("mkearney/nytimes")

Load package

## load nytimes package
library(nytimes)

Examples

Article Search API

## get http response objects for search about sanctions
nytsearch <- nyt_search("sanctions", n = 2000)

## convert response object to data frame
nytsearchdf <- as.data.frame(nytsearch)

## preview data
head(nytsearchdf, 10)

Most Popular API

## get data for most popular stories
nytpop <- nyt_mostpopular(metric = "mostshared",
                          section = "U.S.")

## convert response object to data frame
nytpopdf <- as.data.frame(nytpop)

## preview data
head(nytpopdf)

## get media for each observation
get_media(nytpopdf)

Times Newswire API

## get data from the Times newswire
nytwire <- nyt_timeswire(src = "all",
                         section = "all")

## convert response object to data frame
nytwiredf <- as.data.frame(nytwire)

## preview data
head(nytwiredf)

About

  • These functions were created during the Big Dynamic Data working group sponsored by the Center for Research Methods & Data Analysis at the University of Kansas.

nytimes's People

Contributors

mkearney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nimdvir

nytimes's Issues

Error: couldn't find NYTIMES_KEY environment variable

I followed the first steps to set up the environment as follows:

apikey <- paste0("NYTIMES_KEY=", "mykey____")
file <- file.path(path.expand("~"), ".Renviron")
cat(apikey, file = file, append = TRUE, fill = TRUE)
install.packages("devtools")
devtools::install_github("mkearney/nytimes")
library(nytimes)
nytsearch <- nyt_search("multiculturalism", n = 2000)

But I got this error: Error: couldn't find NYTIMES_KEY environment variable

What have I done wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.