You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3KB

  1. url_nc_cf_search_doc <- function() {
  2. "https://cf.ncsbe.gov/CFDocLkup/DocumentResult/"
  3. }
  4. url_nc_cf_export_search_doc <- function() {
  5. "https://cf.ncsbe.gov/CFDocLkup/ExportSearchResults/"
  6. }
  7. match_report_type <- function(report, collapse = TRUE) {
  8. report <- toupper(report)
  9. reports <- c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  10. valid <- c(
  11. reports,
  12. sub("^RP", "", reports),
  13. gsub("^RP|SA$", "", reports),
  14. sub("RPQTR", "Q", reports)
  15. )
  16. names(valid) <- rep(reports, 4)
  17. x <- names(valid)[match(report, valid)]
  18. if (any(is.na(x))) {
  19. report <- report[is.na(x)]
  20. cli::cli_abort(c("Invalid report {.val {report}}", i = "Valid: {.val {reports}}"))
  21. }
  22. if (!collapse) return(x)
  23. paste(paste0("'", x, "'"), collapse = ", ")
  24. }
  25. req_report_by_year <- function(
  26. year,
  27. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  28. ) {
  29. reports <- match_report_type(report)
  30. req <- request(url_nc_cf_search_doc())
  31. req <- req_url_query(req, year = year, reports = reports)
  32. req
  33. }
  34. req_report_by_year_export <- function(
  35. year,
  36. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  37. ) {
  38. reports <- match_report_type(report)
  39. req <- request(url_nc_cf_export_search_doc())
  40. req <- req_url_query(req, year = year, reports = reports)
  41. req
  42. }