From 6ff11c9e50331e04fd45f77f207329b9dd6c0973 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Mon, 19 Aug 2024 02:07:27 +0100 Subject: [PATCH] re-factor bulletin functions --- NAMESPACE | 4 ++++ R/eq_get_bulletin_urls.R | 10 +++++--- R/eq_get_bulletins.R | 2 +- R/lindol-package.R | 2 ++ man/eq_get.Rd | 5 +--- man/eq_get_bulletin.Rd | 40 +++++--------------------------- man/eq_get_bulletin_urls.Rd | 46 +++++++++++++++++++++++++++++++++++++ pkgdown/_pkgdown.yml | 3 +++ 8 files changed, 70 insertions(+), 42 deletions(-) create mode 100644 man/eq_get_bulletin_urls.Rd diff --git a/NAMESPACE b/NAMESPACE index 0aac528..6e1274b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,10 +4,12 @@ export(eq_build_url) export(eq_data) export(eq_get_bulletin) export(eq_get_bulletin_urls) +export(eq_get_bulletin_urls_) export(eq_get_bulletins) export(eq_get_table) export(eq_process_bulletins) export(eq_process_table) +importFrom(dplyr,across) importFrom(dplyr,bind_rows) importFrom(dplyr,everything) importFrom(dplyr,mutate) @@ -19,7 +21,9 @@ importFrom(rlang,.data) importFrom(rvest,html_table) importFrom(rvest,session) importFrom(stringr,str_detect) +importFrom(stringr,str_remove) importFrom(stringr,str_remove_all) +importFrom(stringr,str_replace) importFrom(stringr,str_replace_all) importFrom(stringr,str_to_title) importFrom(tibble,tibble) diff --git a/R/eq_get_bulletin_urls.R b/R/eq_get_bulletin_urls.R index 7505414..52cd09b 100644 --- a/R/eq_get_bulletin_urls.R +++ b/R/eq_get_bulletin_urls.R @@ -22,7 +22,7 @@ #' @examples #' eq_get_bulletin_urls() #' -#' @rdname eq_get_bulletin +#' @rdname eq_get_bulletin_urls #' @export #' @@ -46,13 +46,17 @@ eq_get_bulletin_urls <- function(.url = "https://earthquake.phivolcs.dost.gov.ph ## Retrieve URLs ---- lapply( X = urls, - FUN = eq_get_links_ + FUN = eq_get_bulletin_urls_ ) |> unlist() } +#' +#' @rdname eq_get_bulletin_urls +#' @export +#' -eq_get_links_ <- function(.url) { +eq_get_bulletin_urls_ <- function(.url) { ## Detect year and month from URL ---- .year <- stringr::str_extract(string = .url, pattern = "[0-9]{4}") |> as.integer() diff --git a/R/eq_get_bulletins.R b/R/eq_get_bulletins.R index e8b759b..022fa0a 100644 --- a/R/eq_get_bulletins.R +++ b/R/eq_get_bulletins.R @@ -46,7 +46,7 @@ eq_get_bulletin <- function(.url) { } #' -#' @rdname eq_get +#' @rdname eq_get_bulletin #' @export #' diff --git a/R/lindol-package.R b/R/lindol-package.R index f73b10f..6eee314 100644 --- a/R/lindol-package.R +++ b/R/lindol-package.R @@ -15,7 +15,9 @@ #' @importFrom httr config #' @importFrom rlang .data #' @importFrom dplyr mutate relocate rename_with bind_rows select everything +#' across #' @importFrom stringr str_to_title str_remove_all str_replace_all str_detect +#' str_remove str_replace #' @importFrom rvest session html_table #' @importFrom tibble tibble #' diff --git a/man/eq_get.Rd b/man/eq_get.Rd index 45aaa6d..c16bb55 100644 --- a/man/eq_get.Rd +++ b/man/eq_get.Rd @@ -1,8 +1,7 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/eq_get.R, R/eq_get_bulletins.R +% Please edit documentation in R/eq_get.R \name{eq_get_table} \alias{eq_get_table} -\alias{eq_get_bulletins} \title{Get earthquake monitoring information from PHIVOLCS earthquake bulletin HTMLs} \usage{ eq_get_table( @@ -11,8 +10,6 @@ eq_get_table( .month = NULL, latest = TRUE ) - -eq_get_bulletins(.url) } \arguments{ \item{.url}{Base URL for PHIVOLCS earthquake bulletins.} diff --git a/man/eq_get_bulletin.Rd b/man/eq_get_bulletin.Rd index 4ec6ec1..1796200 100644 --- a/man/eq_get_bulletin.Rd +++ b/man/eq_get_bulletin.Rd @@ -1,53 +1,25 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/eq_get_bulletin_urls.R, R/eq_get_bulletins.R -\name{eq_get_bulletin_urls} -\alias{eq_get_bulletin_urls} +% Please edit documentation in R/eq_get_bulletins.R +\name{eq_get_bulletin} \alias{eq_get_bulletin} -\title{Get PHIVOLCS earthquake information bulletins} +\alias{eq_get_bulletins} +\title{Retrieve raw information from PHIVOLCS earthquake information bulletins} \usage{ -eq_get_bulletin_urls( - .url = "https://earthquake.phivolcs.dost.gov.ph/", - .year = NULL, - .month = NULL, - latest = TRUE -) - eq_get_bulletin(.url) + +eq_get_bulletins(.url) } \arguments{ \item{.url}{A character value or vector of values for PHIVOLCS earthquake information bulletins} - -\item{.year}{A vector for year (in YYYY format) for which earthquake -bulletins are to be retrieved. The earliest year that can be specified is -2018. If set to NULL (default), all years starting from 2018 to present -year are used.} - -\item{.month}{A vector for month for which earthquake bulletins are -to be retrieved. This can be set as either an integer index (1 for January) -or abbreviation (Jan for January) for full name. If set to NULL (default), -all months are used.} - -\item{latest}{Logical. Should the latest table of earthquake information be -retrieved? Only evaluated if \code{.year = NULL} and \code{.month = NULL}. If TRUE -(default), table of earthquake information for current year and current -month is retrieved. Otherwise, all months for all possible years are -retrieved.} } \value{ -A character vector of URLs for PHIVOLCS earthquake information -bulletins. - A tibble of earthquake information from PHIVOLCS bulletins } \description{ -Get PHIVOLCS earthquake information bulletins - Retrieve raw information from PHIVOLCS earthquake information bulletins } \examples{ -eq_get_bulletin_urls() - urls <- eq_get_bulletin_urls() eq_get_bulletins(urls[1:3]) diff --git a/man/eq_get_bulletin_urls.Rd b/man/eq_get_bulletin_urls.Rd new file mode 100644 index 0000000..a7f7f44 --- /dev/null +++ b/man/eq_get_bulletin_urls.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/eq_get_bulletin_urls.R +\name{eq_get_bulletin_urls} +\alias{eq_get_bulletin_urls} +\alias{eq_get_bulletin_urls_} +\title{Get PHIVOLCS earthquake information bulletins} +\usage{ +eq_get_bulletin_urls( + .url = "https://earthquake.phivolcs.dost.gov.ph/", + .year = NULL, + .month = NULL, + latest = TRUE +) + +eq_get_bulletin_urls_(.url) +} +\arguments{ +\item{.url}{Base URL for PHIVOLCS earthquake bulletins.} + +\item{.year}{A vector for year (in YYYY format) for which earthquake +bulletins are to be retrieved. The earliest year that can be specified is +2018. If set to NULL (default), all years starting from 2018 to present +year are used.} + +\item{.month}{A vector for month for which earthquake bulletins are +to be retrieved. This can be set as either an integer index (1 for January) +or abbreviation (Jan for January) for full name. If set to NULL (default), +all months are used.} + +\item{latest}{Logical. Should the latest table of earthquake information be +retrieved? Only evaluated if \code{.year = NULL} and \code{.month = NULL}. If TRUE +(default), table of earthquake information for current year and current +month is retrieved. Otherwise, all months for all possible years are +retrieved.} +} +\value{ +A character vector of URLs for PHIVOLCS earthquake information +bulletins. +} +\description{ +Get PHIVOLCS earthquake information bulletins +} +\examples{ +eq_get_bulletin_urls() + +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index f03b3ac..71d0260 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -52,10 +52,13 @@ reference: - title: Get contents: - eq_get_table + - eq_get_bulletin_url + - eq_get_bulletin - title: Process contents: - eq_process_table + - eq_process_bulettin - title: Data contents: