knitr::opts_chunk$set(echo = TRUE)
# crayon needs to be explicitly activated in Rmd
options(crayon.enabled = TRUE)
# Hooks needs to be set to deal with outputs
# thanks to fansi logic
old_hooks <- fansi::set_knit_hooks(knitr::knit_hooks, 
                                   which = c("output", "message", "error"))

Get BOM Forecast Town Names and Geographic Locations

BOM maintains a shapefile of forecast town names and their geographic locations. For ease, we'll just use the .dbf file part of the shapefile to extract AAC codes that can be used to add lat/lon values to the forecast data.table that get_precis_forecast() returns. The file is available from BOM's anonymous FTP server with spatial data ftp://ftp.bom.gov.au/anon/home/adfd/spatial/, specifically the DBF file portion of a shapefile, ftp://ftp.bom.gov.au/anon/home/adfd/spatial/IDM00013.dbf.

curl::curl_download(
  "ftp://ftp.bom.gov.au/anon/home/adfd/spatial/IDM00013.dbf",
  destfile = paste0(tempdir(), "AAC_codes.dbf"),
  mode = "wb",
  quiet = TRUE
)

new_AAC_codes <-
  foreign::read.dbf(paste0(tempdir(), "AAC_codes.dbf"), as.is = TRUE)

# convert names to lower case for consistency with bomrang output
names(new_AAC_codes) <- tolower(names(new_AAC_codes))

# reorder columns
new_AAC_codes <- new_AAC_codes[, c(2:3, 7:9)]

data.table::setDT(new_AAC_codes)
data.table::setnames(new_AAC_codes, c(2, 5), c("town", "elev"))
data.table::setkey(new_AAC_codes, "aac")

Show Changes from Last Release

To ensure that the data being compared is from the most recent release, reinstall bomrang from CRAN.

install.packages("bomrang", repos = "http://cran.us.r-project.org")

load(system.file("extdata", "AAC_codes.rda", package = "bomrang"))

(AAC_code_changes <- diffobj::diffPrint(new_AAC_codes, AAC_codes))

Save the data

Save the stations' metadata and changes to disk for use in bomrang.

if (!dir.exists("../inst/extdata")) {
  dir.create("../inst/extdata", recursive = TRUE)
}

AAC_codes <- new_AAC_codes

save(AAC_codes,
     file = "../inst/extdata/AAC_codes.rda",
     compress = "bzip2"
)

save(AAC_code_changes,
     file = "../inst/extdata/AAC_code_changes.rda",
     compress = "bzip2")

Session Info

sessioninfo::session_info()


ToowoombaTrio/BOMRang documentation built on Jan. 31, 2023, 3:10 p.m.