Skip to contents

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 = paste0("https://collaboration.cmc.ec.gc.ca/cmc/climate/",
    "Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv"),
  quiet = FALSE,
  debug = 0
)

Arguments

name

character value use in a name search. The search is done using agrep() with the supplied max.distance value and with ignore.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 has changed over time, owing to changes with the Government of Canada website. For example, from 2024-05-06, the link at Reference 1 worked. However, the author noticed on 2025-07-23 that this URL did not provide files that held a "Climate ID" column, and so the default was changed to Reference 2 on that date. Users are asked to post an issue on the github.com/dankelley/dod/issues website, if they find that dod.met.index() either reports errors, or if the data frame returned by this function lacks a column labelled Climate ID, since values in that column are what is needed as the id parameter by dod.met().

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 called silent, but it was renamed to match the corresponding argument in curl::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.

References

  1. Default url from 2024-05-06 to 2025-07-23: https://dd.weather.gc.ca/climate/observations/climate_station_list.csv.

  2. Default url from 2025-07-23 onward: paste0("https://collaboration.cmc.ec.gc.ca/cmc/climate/", "Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv).

Author

Dan Kelley

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", "Name", "Climate.ID")]
    # focus on the ones in Nova Scotia
    i <- i[grep("nova scotia", i$Province, ignore.case = TRUE), ]
    # Show start/end times for hourly data.
    i[, c("Name", "Station.ID", "HLY.First.Year", "HLY.Last.Year")]
    #>                           Name Station.ID HLY.First.Year HLY.Last.Year
    #> 8196                   HALIFAX       6355             NA            NA
    #> 8197                   HALIFAX       6356           1953          1963
    #> 8198           HALIFAX CITADEL       6357             NA            NA
    #> 8199           HALIFAX COMMONS      49128           2010          2011
    #> 8200          HALIFAX DOCKYARD      43405           2004          2025
    #> 8201 HALIFAX STANFIELD INT\'L A      53938           2019          2025
    #> 8202 HALIFAX STANFIELD INT\'L A       6358           1961          2012
    #> 8203 HALIFAX STANFIELD INT\'L A      50620           2012          2025
    #> 8204          HALIFAX KOOTENAY      43124           2004          2025
    #> 8205      HALIFAX WINDSOR PARK      43403           2004          2025
}