Skip to content

Commit

Permalink
Merge pull request #3 from QuantGov/dev
Browse files Browse the repository at this point in the history
final codebase with all the fixes and cran compliances
  • Loading branch information
gadia-aayush authored Oct 2, 2023
2 parents 02012a2 + 7e94c81 commit af756b8
Show file tree
Hide file tree
Showing 50 changed files with 112 additions and 104 deletions.
15 changes: 11 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
Type: Package
Package: regcensus
Title: Accessing Data from the RegCensusAPI
Title: Accessing Data from the 'RegCensusAPI'
Version: 1.0.0
Author: QuantGov
Maintainer: QuantGov <info@quantgov.org>
Description: Allowing users to access data from the RegCensusAPI. The RegCensusAPI is an API client that connects to the RegData regulatory restrictions data by the Mercatus Center at George Mason University. RegData uses machine learning algorithms to quantify the number of regulatory restrictions in a jurisdiction. You can find out more about RegData from 'QuantGov website' <https://www.quantgov.org>.
Authors@R: c(
person("Jonathan", "Nelson", , "jnelson@mercatus.gmu.edu",
role = c("aut", "cre")),
person("Thurston", "Powers", , "tpowers@mercatus.gmu.edu",
role = c("aut")),
person("Aayush", "Gadia", , "agadia@mercatus.gmu.edu",
role = c("aut")),
person("Mercatus Center", email = "info@quantgov.org",
role = c("cph", "fnd")))
Description: Allowing users to access data from the 'RegCensusAPI'. The 'RegCensusAPI' is an API client that connects to the 'RegData' regulatory restrictions data by the 'Mercatus Center' at 'George Mason University'. 'RegData' uses machine learning algorithms to quantify the number of regulatory restrictions in a jurisdiction. You can find out more about 'RegData' from 'QuantGov website' <https://www.quantgov.org>.
License: MIT+ file LICENSE
URL: https://github.com/QuantGov/regcensus-api-client-R
BugReports: https://github.com/QuantGov/regcensus-api-client-R/issues
Expand Down
4 changes: 2 additions & 2 deletions R/agency_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param keyword search for keyword in agency name
#' @return url as a string
#' @examples
#' agency_url(jurisdiction_id = 38, keyword = "test_word")
#' \dontrun{agency_url(jurisdiction_id = 38, keyword = "test_word")}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -20,7 +20,7 @@ agency_url <- function(jurisdiction_id, keyword) {
} else if (!is.null(jurisdiction_id)) {
url_call <- paste0(url, "/agencies?", "jurisdiction=", jurisdiction_id)
} else {
print("Must include either 'jurisdiction_id' or 'keyword.'")
message("Must include either 'jurisdiction_id' or 'keyword.'")
return()
}
return(url_call)
Expand Down
4 changes: 2 additions & 2 deletions R/get_agencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param verbose prints out the url of the API call, default value of 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_agencies(jurisdiction_id = 38, keyword = "test")
#' \dontrun{get_agencies(jurisdiction_id = 38, keyword = "test")}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -17,7 +17,7 @@
get_agencies <- function(jurisdiction_id = NULL, keyword = NULL, verbose = 0) {
url_call <- agency_url(jurisdiction_id, keyword)
if (verbose) {
print(paste0("API call: ", url_call))
message(paste0("API call: ", url_call))
}
output <- clean_columns(fromJSON(content(GET(url_call), as = "parsed")))
return(output)
Expand Down
2 changes: 1 addition & 1 deletion R/get_datafinder.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @return Returns dataframe with the series and years available,
#' along with the endpoints to access the data
#' @examples
#' get_datafinder(jurisdiction = 38)
#' \dontrun{get_datafinder(jurisdiction = 1)}
#' @import httr
#' @import jsonlite
#' @import stats
Expand Down
4 changes: 2 additions & 2 deletions R/get_document_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#' default value is 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_document_values(
#' \dontrun{get_document_values(
#' series = 33, jurisdiction = 38,
#' year = 2018, label = "111"
#' )
#' )}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/get_documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' documentation, the source name, source citation,
#' source url and documentation.
#' @examples
#' get_documentation()
#' \dontrun{get_documentation()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
12 changes: 6 additions & 6 deletions R/get_documents.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param verbose prints out the url of the API call, default value of 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_documents(jurisdiction_id = 38, date = 2018)
#' \dontrun{get_documents(jurisdiction_id = 38, date = 2022)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -20,18 +20,18 @@
get_documents <- function(document_id = NULL, jurisdiction_id = NULL,
date = NULL, document_type = 1, verbose = 0) {
if (!is.null(document_id)) {
message <- paste0("document_id is no longer accessible as of version 1.0.",
" Use previous version of API or use jurisdiction_id",
" and date combination")
print(message)
text <- paste0("document_id is no longer accessible as of version 1.0.",
" Use previous version of API or use jurisdiction_id",

Check warning on line 24 in R/get_documents.R

View workflow job for this annotation

GitHub Actions / macos-latest (release)

file=R/get_documents.R,line=24,col=22,[indentation_linter] Hanging indent should be 19 spaces but is 22 spaces.

Check warning on line 24 in R/get_documents.R

View workflow job for this annotation

GitHub Actions / ubuntu-latest (devel)

file=R/get_documents.R,line=24,col=22,[indentation_linter] Hanging indent should be 19 spaces but is 22 spaces.
" and date combination")
message(text)
return()
} else if (!is.null(jurisdiction_id) && !is.null(date)) {
return(get_values(series = 1, jurisdiction = jurisdiction_id,
year = date,
document_type = document_type,
summary = FALSE))
} else {
print("Must include jurisdiction_id and date")
message("Must include jurisdiction_id and date")
return()
}
}
4 changes: 2 additions & 2 deletions R/get_endpoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#' @return Returns the endpoint, e.g. '/state-summary' for summary-level state
#' data
#' @examples
#' get_endpoint(
#' \dontrun{get_endpoint(
#' series = c(28, 33, 36), jurisdiction = 38,
#' year = c(1970, 2003, 2004, 2018), document_type = 1
#' )
#' )}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
4 changes: 2 additions & 2 deletions R/get_industries.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param verbose prints out the url of the API call, default value of 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_industries()
#' \dontrun{get_industries()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -19,7 +19,7 @@ get_industries <- function(keyword = NULL, label_level = 3,
label_source = NULL, verbose = 0) {
url_call <- industries_url(keyword, label_level, label_source)
if (verbose) {
print(paste0("API call: ", url_call))
message(paste0("API call: ", url_call))
}
output <- clean_columns(fromJSON(content(GET(url_call), as = "parsed")))
return(output)
Expand Down
4 changes: 2 additions & 2 deletions R/get_jurisdictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param verbose prints out the url of the API call, default value of 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_jurisdictions()
#' \dontrun{get_jurisdictions()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -15,7 +15,7 @@
get_jurisdictions <- function(verbose = 0) {
url_call <- jurisdictions_url()
if (verbose) {
print(paste0("API call: ", url_call))
message(paste0("API call: ", url_call))
}
output <- clean_columns(fromJSON(content(GET(url_call), as = "parsed")))
return(output)
Expand Down
12 changes: 8 additions & 4 deletions R/get_reading_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#' default value is 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_reading_time(
#' jurisdiction = 38,
#' year = array(c(1970, 2003, 2004, 2018, 2020))
#' )
#' \dontrun{get_reading_time(
#' jurisdiction = 45,
#' year = array(c(2022, 2023))
#' )}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -55,6 +55,10 @@ get_reading_time <- function(series = 2, jurisdiction, year, document_type = 1,
label_source = "NAICS", version = NULL,
download = FALSE, page = NULL, date = NULL,
verbose = 0) {
#for demo example
if (jurisdiction == 0) {
return(NULL)
}
results <- get_values(
series, jurisdiction, year, document_type, summary, date_is_range,
country, agency, cluster, label, industry, filtered, label_level,
Expand Down
4 changes: 2 additions & 2 deletions R/get_series.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param verbose prints out the url of the API call, default value of 0
#' @return Returns pandas dataframe with the metadata
#' @examples
#' get_series()
#' \dontrun{get_series()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -15,7 +15,7 @@
get_series <- function(verbose = 0) {
url_call <- series_url()
if (verbose) {
print(paste0("API call: ", url_call))
message(paste0("API call: ", url_call))
}
output <- clean_columns(fromJSON(content(GET(url_call), as = "parsed")))
return(output)
Expand Down
16 changes: 8 additions & 8 deletions R/get_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#' @return Returns pandas dataframe with the values and various metadata,
#' and returns empty if required parameters are not given
#' @examples
#' get_values(
#' \dontrun{get_values(
#' series = array(c(1, 28, 33, 36)), jurisdiction = 38,
#' year = array(c(1970, 2003, 2004, 2018, 2020)), country = TRUE
#' )
#' )}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down Expand Up @@ -79,7 +79,7 @@ get_values <- function(series, jurisdiction, year, document_type = 1,
error = function() {
paste0("No data was found for these parameters.",
" For this jurisdiction, consider the following: \n")
print(as.data.frame(get_datafinder(jurisdiction, document_type)))
message(as.data.frame(get_datafinder(jurisdiction, document_type)))
return()
}
)
Expand All @@ -100,7 +100,7 @@ get_values <- function(series, jurisdiction, year, document_type = 1,
# list of available series, and function returns empty.
} else {
warning("Valid series ID required. Select from the following list:")
print(pretty(list_series()))
message(pretty(list_series()))
return()
}

Expand All @@ -115,7 +115,7 @@ get_values <- function(series, jurisdiction, year, document_type = 1,
# If no appropriate jurisdiction is given, prints warning message
# jurisdictions, and function returns empty.
warning("Valid jurisdiction ID required. Select from the following list:")
print(pretty(list_jurisdictions()))
message(pretty(list_jurisdictions()))
return()
}

Expand Down Expand Up @@ -180,9 +180,9 @@ get_values <- function(series, jurisdiction, year, document_type = 1,
# list of available dates for the given jurisdiction(s),
# and function returns empty.
} else {
print("Valid date is required. Select from the following list:")
message("Valid date is required. Select from the following list:")
dates <- list_dates(jurisdiction)
print(dates)
message(dates)
return()
}

Expand Down Expand Up @@ -223,7 +223,7 @@ get_values <- function(series, jurisdiction, year, document_type = 1,

# Prints the url call if verbosity is flagged
if (verbose) {
cat(paste0("API call: ", gsub(" ", "%20", url_call)))
message(paste0("API call: ", gsub(" ", "%20", url_call)))
}

# Allows user to manually select a page of the output
Expand Down
2 changes: 1 addition & 1 deletion R/industries_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param label_source classification standard (NAICS, BEA, SOC)
#' @return url as a string
#' @examples
#' industries_url("test", 323, "NAICS")
#' \dontrun{industries_url("test", 323, "NAICS")}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/jurisdictions_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Gets url call for jurisdictions endpoint.
#' @return url as a string
#' @examples
#' jurisdictions_url()
#' \dontrun{jurisdictions_url()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/list_agencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param reverse reverses the key-value mapping, default value of FALSE
#' @return Returns dictionary containing names of agencies and associated IDs
#' @examples
#' list_agencies(jurisdiction_id = 38, reverse = TRUE)
#' \dontrun{list_agencies(jurisdiction_id = 38)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/list_clusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param reverse reverses the key-value mapping, default value of FALSE
#' @return Returns dictionary containing names of clusters & associated IDs
#' @examples
#' list_clusters(reverse = TRUE)
#' \dontrun{list_clusters()}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/list_dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param document_type ID for type of document
#' @return Returns list of dates available for the jurisdiction
#' @examples
#' list_dates(jurisdiction_id = 38)
#' \dontrun{list_dates(jurisdiction_id = 38)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
5 changes: 3 additions & 2 deletions R/list_document_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#' @param verbose prints out the url of the API call
#' @return Returns dictionary containing names of documenttypes & associated IDs
#' @examples
#' list_document_types(jurisdiction_id = 38, reverse = FALSE, verbose = 0)
#' \dontrun{list_document_types(jurisdiction_id = 65,
#' reverse = FALSE, verbose = 0)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -23,7 +24,7 @@ list_document_types <- function(jurisdiction_id = NULL,
url_call <- paste0(url, "/documenttypes")
}
if (verbose) {
print(paste0("API call: ", url_call))
message(paste0("API call: ", url_call))
}
response <- fromJSON(content(GET(url_call), as = "parsed"))
document_types <- response[!is.na(response$document_type), ]
Expand Down
2 changes: 1 addition & 1 deletion R/list_industries.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param reverse reverses the key-value mapping, default value of FALSE
#' @return Returns dictionary containing names of industries and associated IDs
#' @examples
#' list_industries(only_id = TRUE, reverse = FALSE)
#' \dontrun{list_industries(only_id = TRUE, reverse = FALSE)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/list_jurisdictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param reverse reverses the key-value mapping, default value of FALSE
#' @return Returns dictionary containing names of jurisdictions & associated IDs
#' @examples
#' list_jurisdictions(reverse = TRUE)
#' \dontrun{list_jurisdictions(reverse = TRUE)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
2 changes: 1 addition & 1 deletion R/list_series.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param reverse reverses the key-value mapping, default value of FALSE
#' @return Returns dictionary containing names of series and associated IDs
#' @examples
#' list_series(reverse = FALSE)
#' \dontrun{list_series(reverse = FALSE)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
6 changes: 3 additions & 3 deletions R/print_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param output key-value mapping of the output
#' @return None
#' @examples
#' print_error(list(message = "test"))
#' \dontrun{print_error(list(message = "test"))}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand All @@ -15,10 +15,10 @@
print_error <- function(output) {
tryCatch(
{
print(paste0("ERROR: ", output$message))
message(paste0("ERROR: ", output$message))
},
error = function() {
print(paste0("ERROR: ", output$errorMessage))
message(paste0("ERROR: ", output$errorMessage))
}
)
return()
Expand Down
3 changes: 2 additions & 1 deletion R/reading_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' how many words the document has. The function assumes an 8 hour work-day,
#' a 5 day work-week, and a 50 week work-year.
#' @examples
#' reading_time(1200000, workday = 8, workweek = 5, workyear = 50)
#' \dontrun{reading_time(1200000, workday = 8,
#' workweek = 5, workyear = 50)}
#' @import jsonlite
#' @import stringr
#' @import httr
Expand Down
Loading

0 comments on commit af756b8

Please sign in to comment.