This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathupdate_forecast_towns.R
68 lines (58 loc) · 2.25 KB
/
update_forecast_towns.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#' Update internal database with latest BOM forecast towns
#'
#' @description
#' Download the latest select forecast towns from the \acronym{BOM} server and
#' update internal database of précis forecast town names and \acronym{AAC}
#' codes used by \code{\link{get_precis_forecast}}. There is no need to use
#' this unless you know that a forecast town exists in a more current version of
#' the \acronym{BOM} précis forecast town name database that is not available in
#' the database distributed with \CRANpkg{bomrang}. In fact, for
#' reproducibility purposes, users are discouraged from using this function.
#'
#' @examples
#' \dontrun{
#' update_forecast_towns()
#' }
#' @return Updated database of \acronym{BOM} précis forecast towns
#'
#' @references
#' Data are sourced from: Australian Bureau of Meteorology (\acronym{BOM})
#' webpage, \dQuote{Weather Data Services},
#' \url{http://www.bom.gov.au/catalogue/data-feeds.shtml}
#'
#' @author Adam H. Sparks, \email{adamhsparks@@gmail.com}
#' @export update_forecast_towns
update_forecast_towns <- function() {
message(
"This will overwrite the current internal database of forecast towns.\n",
"If reproducibility is necessary, you may not wish to proceed.\n",
"Do you understand and wish to proceed (Y/n)?\n"
)
answer <-
readLines(con = getOption("bomrang.connection"), n = 1)
answer <- toupper(answer)
if (answer %notin% c("Y", "YES")) {
stop("Forecast towns were not updated.",
call. = FALSE)
}
message("Updating forecast towns.\n")
original_timeout <- options("timeout")[[1]]
options(timeout = 300)
on.exit(options(timeout = original_timeout))
# fetch new database from BOM server
curl::curl_download(
"ftp://ftp.bom.gov.au/anon/home/adfd/spatial/IDM00013.dbf",
destfile = file.path(tempdir(), "AAC_codes.dbf"),
mode = "wb",
quiet = TRUE
)
# import BOM dbf file
AAC_codes <-
foreign::read.dbf(file.path(tempdir(), "AAC_codes.dbf"), as.is = TRUE)
AAC_codes <- AAC_codes[, c(2:3, 7:9)]
# overwrite the existing isd_history.rda file on disk
message("\nOverwriting existing database of forecast towns and AAC codes.\n")
fname <-
system.file("extdata", "AAC_codes.rda", package = "bomrang")
save(AAC_codes, file = fname, compress = "bzip2")
}