Look up information on a Canadian meteorological station, by
a fuzzy search on information stored on a gc.ca website. The main
use is to find a station ID, to be used with dod.met()
.
Usage
dod.met.index(
name,
max.distance = 0.1,
url = "https://dd.weather.gc.ca/climate/observations/climate_station_list.csv",
quiet = FALSE,
debug = 0
)
Arguments
- name
character value use in a name search. The search is done using
agrep()
with the suppliedmax.distance
value and withignore.case
set to TRUE.- max.distance
numerical value passed to
agrep()
in the station-name search.- url
the URL of the source file. The default value was tested on May 6, 2024, but this agency tends to change the file location (and data format) without notice, so if you find an error in downloading, please report it as an issue on the project github site.
- quiet
a logical value, passed to
curl::curl_download()
, which does the downloading. If this is TRUE (the default), then the work is done quietly. Until version version 0.1.12, this parameter was calledsilent
, but it was renamed to match the corresponding argument incurl::curl_download()
, which may be more familiar to users.- debug
an integer value indicating the level of debugging. If this exceeds 0, then some debugging messages will be printed. This value is passed down to related functions, but with 1 subtracted for each pass.
Details
The source file is at the web location named by the url
parameter. (Please contact the author, if the default value fails.
It was known to work in May of 2024, but this agency might change
the file location or format at any time.) The results are a data
frame with information that ought to be easy to interpret. For use
with dod.met()
, the ID field that is of use is named
"Climate.ID"
. See “Examples” for what might be of
interest for hourly data.
Examples
if (interactive()) { # sidestep a pkgdown::build_site() error
# Get index of meteorological data for Halifax, N.S.
library(dod)
i <- dod.met.index("halifax")
names(i) # see what's in these files
i[, c("Province", "Station.Name", "Climate.ID")]
# focus on the ones in Nova Scotia
NS <- grep("nova", i$Province, ignore.case = TRUE)
i <- i[NS, ]
i[, c("Province", "Station.Name", "Climate.ID")]
}