download.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.
download.met( id, year, month, deltat, type = "xml", destdir = ".", destfile, force = FALSE, quiet = FALSE, debug = getOption("oceDebug") )
A number giving the "Station ID" of the station of interest. If not
id defaults to 6358, for Halifax International Airport. See
A number giving the year of interest. Ignored unless
year is not given, it defaults to the present year.
A number giving the month of interest. Ignored unless
month is not given, it defaults to the present
Optional character string indicating the time step of the
desired dataset. This may be
deltat is not given, it defaults to
String indicating which type of file to download, either
"xml" (the default) for an XML file or
"csv" for a CSV file.
Optional string indicating the directory in which to store
downloaded files. If not supplied,
"." is used, i.e. the data file
is stored in the present working directory.
Optional string indicating the name of the file. If not supplied, the file name is constructed from the other parameters of the function call, so subsequent calls with the same parameters will yield the same result, thus providing the key to the caching scheme.
Logical value indicating whether to force a download, even if the file already exists locally.
Logical value passed to
an integer specifying whether debugging information is
to be printed during the processing. This is a general parameter that
is used by many
oce functions. Generally, setting
turns off the printing, while higher values suggest that more information
be printed. If one function calls another, it usually reduces the value of
debug first, so that a user can often obtain deeper debugging
by specifying higher
String indicating the full pathname to the downloaded file.
If this function fails, users might try using Gavin Simpson's
package (reference 2). This package maintains a copy of the Environment
Canada listing of stations, and its
find_station() function provides an easy
way to determine Station IDs. After that, its
hcd_hourly function (and
related functions) make it easy to read data. These data can then be
converted to the
met class with
as.met(), although doing so leaves many
important metadata blank.
Environment Canada website for Historical Climate Data
canadaHCD package on GitHub