dod.met() attempts to download data from Environment Canada's
historical-data website, and to cache the files locally. Lacking a published
API, this function must rely on reverse-engineering of queries handled by
that web server. For that reason, it is brittle.
Arguments
- id
a number giving the "Station ID" of the station of interest. If not provided,
iddefaults to 43405, for Halifax Dockyard. (Previously, the default was 6358, for Halifax International Airport, but in March 2024 it was noticed that 6358 held no data.) See “Details”.- year
a number giving the year of interest. Ignored unless
deltatis"hour". Ifyearis not given, it defaults to the present year.- month
a number giving the month of interest. Ignored unless
deltatis"hour". Ifmonthis not given, it defaults to the present month. As a special case, if neitheryearnormonthis given, and it is the first day of the month,dod.met()goes back one month, to avoid returning a file with no data.- deltat
an optional character string indicating the time step of the desired dataset. This may be
"hour"or"month". Ifdeltatis not given, it defaults to"hour".- type
a character value indicating which type of file to download, either
"xml"(the default) for an XML file or"csv"for a CSV file.- destdir
a character value indicating the directory in which to store downloaded files.
- age
a numerical value indicating a time interval, in days. If the file to be downloaded from the server already exists locally, and was created less than
agedays in the past, it will not be downloaded again. Settingage=0forces a download, so that existing files will always be updated. By contrast, settingageto a negative number prevents the updating of files that already exist locally, regardless of their age.- 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
If this function fails, users might try using Gavin Simpson's canadaHCD
package (reference 2) or the weathercan package (reference 3).
References
Environment Canada website for Historical Climate Data
https://climate.weather.gc.ca/index_e.htmlGavin Simpson's
canadaHCDpackage on GitHubhttps://github.com/gavinsimpson/canadaHCDWeathercan package
https://github.com/ropensci/weathercan/tree/main
See also
Other functions that download files:
dod.amsr(),
dod.buoy(),
dod.coastline(),
dod.ctd(),
dod.ctd.bats(),
dod.ctd.bbmp(),
dod.ctd.gtspp(),
dod.ctd.itp(),
dod.tideGauge(),
dod.topo()
Examples
# Meteorological data for Halifax, Nova Scotia.
if (interactive()) { # pkgdown::build_site() cannot handle downloads
library(dod)
destdir <- tempdir(check = TRUE)
metFile <- dod.met(43405, destdir = destdir)
if (requireNamespace("oce", quietly = TRUE) &&
requireNamespace("XML", quietly = TRUE)) {
library(oce)
met <- read.met(metFile)
t <- met[["time"]]
p <- met[["pressure"]]
oce.plot.ts(t, p, ylab = "Atm. Pressure [Pa]")
}
unlink(destdir, recursive = TRUE)
}