Coder Social home page Coder Social logo

regsgov's Introduction

R Client for the U.S. Federal Regulations API

Build Status (Automated tests fail at the moment as the DEMO_KEY has been revoked by regulations.gov and I don't want to put my actual key in here)

This package provides access to the API for United States regulations at regulations.gov. The API provides access to all regulations, associated documents, and comments collected. The API returns basic details about each regulation and associated documents and provides the URLs for HTML, PDF, and plan text versions when available.

Installing the package

The package can be installed from GitHub as follows:

if (!require('remotes')) {
    install.packages('remotes')
}
remotes::install_github('bowdoincollege/regsgov')
library(regulations)

Example Code

Below are some examples of possible uses of the package.

Simple use to search regulations.gov for documents with the keyword katahdin in them.

katahdin <- documents(apikey='DEMO_KEY', keywords='katahdin')
katahdin$totalNumRecords
katahdin$content[[1]]

Find documents related to a specific docketID. In this case we are looking for the comments on a particular regulation. As the API is limited to 1,000 documents per request, we loop through the results and collect the results into a single data.frame. This example does not fetch all ~780,000 but could easily be adapted to do so.

# Create a data frame to hold the collected results
comments <- data.frame(NULL)

# Start at first (`start_offset`) and accumulate `end_offset` documents
start_offset <- 0
end_offset   <- 100
# fetch `nresults` documents at a time... 
nresults     <- 10

# Loop through and accumulate documents into `comments` data.frame
offset <- start_offset
while (offset < end_offset) {
    # Fetch the next chunk
    temp <- documents(apikey='DEMO_KEY', docketID = 'DOI-2017-0002', 
                        offset = offset, nresults = nresults)
    print(paste(offset, "to", offset+nresults, "of", temp$totalNumRecords, "documents"))
    # Add result to collected results
    comments <- rbind(comments, temp$content)
    # Advance to next offset
    offset <- offset + nresults
}

# Display some of the data
head(comments$commentText)

API Key

To do more than a few small queries you will need to request an API Key to replace the DEMO_KEY shown above. The process is simple and quick using the API Key Requetst form on the regulations.gov site. Your unique individual key will be emailed to you. Replace DEMO_KEY in the examples above with your key.

Developing

Some notes for how to load while developing, using devtools:

if (!require('devtools')) {
    install.packages('devtools')
}
devtools::load_all()
devtools::use_testthat()
devtools::test()
devtools::check()

To run the same test cases that TravisCI runs, use:

R CMD build .
R CMD check 

regsgov's People

Contributors

stephenhouser avatar markwh avatar

Watchers

James Cloos avatar  avatar  avatar

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.