knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(regulationsgov)
The package regulationsgov is designed to enable users to access and engage with textual data from the Regulations.gov API.
You can install the development version of regulationsgov from GitHub with:
# install.packages("devtools") remotes::install_github("q-w-a/regulationsgov")
To access the Regulations.gov API, you will need to obtain an API key here.
Once you have this key, you can provide it to every time you call one of the functions requiring authentication using the key
argument, but it may be easiest to set it up as an environmental variable. You can do this with the following function.
library(regulationsgov) set_datagov_key("PUT_KEY_HERE")
If you run set_datagov_key
, you don't need to provide the key as an argument to functions in this package. You only need to run it once. However, if you choose to not set it up, you can just provide the key to the functions requiring authentication.
For example, here we retrieve all comment metadata, including the download links, for the docket CMS-2014-0063. First, we do so assuming we have set up the key. See the Obtaining Data vignette for more information on how to use the endpoint
argument.
# retrieve all comments for the docket CMS-2014-0063 comments_CMS_2014_0063 <- get_all_comments(endpoint = "document", docketId = "CMS-2014-0063")
If the key is not set up, then we provide the key with the key
argument. Here, you need to replace DEMO_KEY
with your specific key unless you are running a very limited number of calls (the rate limit for DEMO_KEY
is much lower than an ordinary API key).
# retrieve all comments for the docket CMS-2014-0063 comments_CMS_2014_0063 <- get_all_comments(endpoint = "document", docketId = "CMS-2014-0063", key = "DEMO_KEY")
After running this command, if needed you can access it as an environmental variable with
Sys.getenv("DATA_GOV_KEY")
but this will likely be unnecessary for use of the functions in this package.
Here, we obtain document and metadata for all documents associated with the docket FDA-2009-N-0501.
library(dplyr) documents <- regulationsgov::get_all_documents( docketId = "FDA-2009-N-0501") str(documents)
In this case, there are only 13 comments associated with docket FDA-2009-N-0501
. We can obtain them with the function
get_all_comments
. You might notice the same individual has submitted multiple comments, which we also can verify here.
comments <- regulationsgov::get_all_comments(endpoint = "document", docketId ="FDA-2009-N-0501") comments %>% select(data_id, data_title, data_stateProvinceRegion) %>% str()
Of particular interest may be the fileUrl
column, which allows us to download the text.
For example, to download any attachments for the comments and place them in the directory comments_FDA_2009_N_0501
, we can run
download_all(data_frame = comments, dest = "../comments_FDA_2009_N_0501", quiet = TRUE)
and to download the documents themselves to the directory docs_FDA_2009_N_0501
we can run the following.
download_all(data_frame = documents, dest = "../docs_FDA_2009_N_0501", quiet = TRUE)
If we don't want to download the text but instead want the text included in the data frame, you can use the add_text
function. This function adds a column text
where each entry contains all the processed text from any attachments for that document or comment.
comments <- add_text(comments) comments %>% select(data_id, data_comment, text) %>% str()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.