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 Marine Zones

BOM maintains a shapefile of forecast marine zone 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 locations to the forecast data.table that get_coastal_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/IDM00003.dbf.

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

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

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

# reorder columns
new_marine_AAC_codes <- new_marine_AAC_codes[, c(1, 3, 4, 5, 6, 7)]

data.table::setDT(new_marine_AAC_codes)
data.table::setkey(new_marine_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", "marine_AAC_codes.rda", package = "bomrang"))

(
  marine_AAC_code_changes <-
    diffobj::diffPrint(new_marine_AAC_codes, marine_AAC_codes)
)

Save Marine Locations Data and Changes

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

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

marine_AAC_codes <- new_marine_AAC_codes

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

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

Session Info

sessioninfo::session_info()


adamhsparks/BOMRang documentation built on Jan. 31, 2023, 4:49 a.m.