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 pathparse_ag_bulletin.R
83 lines (82 loc) · 3.19 KB
/
parse_ag_bulletin.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#' Parse local BOM agriculture bulletin XML file(s) for select stations
#'
#' Parse local \acronym{BOM} agriculture bulletin \acronym{XML} file(s) and
#' return a data frame for a specified state or territory or all Australia.
#'
#' @param state Required value of an Australian state or territory as full name
#' or postal code. Fuzzy string matching via \code{\link[base]{agrep}} is
#' done.
#'
#' @param filepath A string providing the directory location of the précis
#' file(s) to parse. See Details for more.
#'
#' @details Allowed state and territory postal codes, only one state per request
#' or all using \code{AUS}.
#' \describe{
#' \item{ACT}{Australian Capital Territory (will return NSW)}
#' \item{NSW}{New South Wales}
#' \item{NT}{Northern Territory}
#' \item{QLD}{Queensland}
#' \item{SA}{South Australia}
#' \item{TAS}{Tasmania}
#' \item{VIC}{Victoria}
#' \item{WA}{Western Australia}
#' \item{AUS}{Australia, returns forecast for all states, NT and ACT}
#' }
#'
#' @details The \var{filepath} argument will only accept a directory where files
#' are located for parsing. DO NOT supply the full path including the file name.
#' This function will only parse the requested state or all of Australia in the
#' same fashion as \code{\link{get_precis_forecast}}, provided that the files
#' are all present in the directory.
#'
#' @return A \code{\link[data.table]{data.table}} of Australia \acronym{BOM}
#' agricultural bulletin information. For full details of fields and units
#' returned see Appendix 3 in the \CRANpkg{bomrang} vignette, use \cr
#' \code{vignette("bomrang", package = "bomrang")} to view.
#'
#' @examples
#' \donttest{
#' # parse the ag bulletin for Queensland
#'
#' # download to tempfile() using basename() to keep original name
#' download.file(url = "ftp://ftp.bom.gov.au/anon/gen/fwo/IDQ60604.xml",
#' destfile = file.path(tempdir(),
#' basename("ftp://ftp.bom.gov.au/anon/gen/fwo/IDQ60604.xml")),
#' mode = "wb")
#'
#' BOM_bulletin <- parse_ag_bulletin(state = "QLD",
#' filepath = tempdir())
#'
#' BOM_bulletin
#'}
#'
#' @references
#' Agricultural observations are retrieved from the Australian Bureau of
#' Meteorology (\acronym{BOM}) Weather Data Services Agriculture Bulletins, \cr
#' \url{http://www.bom.gov.au/catalogue/observations/about-agricultural.shtml}
#'
#' and
#'
#' Australian Bureau of Meteorology (\acronym{BOM})) Weather Data Services
#' Observation of Rainfall, \cr
#' \url{http://www.bom.gov.au/climate/how/observations/rain-measure.shtml}
#'
#' Station location and other metadata are sourced from the Australian Bureau of
#' Meteorology (\acronym{BOM}) webpage, Bureau of Meteorology Site Numbers: \cr
#' \url{http://www.bom.gov.au/climate/cdo/about/site-num.shtml}
#'
#' @author Adam H. Sparks, \email{adamhsparks@@gmail.com} and Paul Melloy
#' \email{paul@@melloy.com.au}
#'
#' @seealso \link{get_ag_bulletin}
#'
#' @export parse_ag_bulletin
#'
parse_ag_bulletin <- function(state, filepath) {
the_state <- .check_states(state)
location <- .validate_filepath(filepath)
bulletin_out <-
.return_bulletin(file_loc = location, cleaned_state = the_state)
return(bulletin_out)
}