knitr::opts_chunk$set(collapse = TRUE, comment = "#>", cache = FALSE) options(tibble.width = 120)
Access Canadian Historical Climate Data from R. The Government of Canada's Historical Climate Data website provides access to hourly, daily, and monthly weather records for stations throughout Canada.
These are raw data that have undergone some quality control, but issues such
as changes in station location are unmanged; the data for the original
stationID
stops at a certain point and a new stationID
continues recording.
For a more curated data set for climate change research at broad spatial and
temporal scales see the Adjusted and Homogenized Canadian Climate Data (AHCCD).
canadaHCD is still under active development towards a 0.1 release. In the meantime, if you wish to use the package, please install it from this github repo, which is most easily achieved using Hadley Wickham's remotes package:
## install.packages("devtools") remotes::install_github("gavinsimpson/canadaHCD")
Say I'm interested in climate data for stations in Yellowknife, I can search
for all known stationID
s with "Yellowknife"
in their name using
find_station()
library("canadaHCD") find_station("Yellowknife")
To download the monthly HCD from YELLOWKNIFE HYDRO
I can use hcd_monthly()
,
providing it with the StationID
for that particular weather station
yh <- hcd_monthly(1707)
The data are returned as a tibble
(a tbl_df
), which shows a compact version of the data frame.
yh
You should be able to work with these objects mostly as if they were data frames.
Allthough not yet exposed through any functions in the package, you can
access a snapshot of the station metadata via the canadaHCD:::station_data
data frame.
canadaHCD:::station_data
If we wanted to know which resolutions of data were available for the
YELLOWKNIFE HYDRO
station, we can extract certain columns from the station
data object
id <- grep("YELLOWKNIFE HYDRO", canadaHCD:::station_data$Name) vars <- c("HourlyFirstYr", "HourlyLastYr", "DailyFirstYr", "DailyLastYr", "MonthlyFirstYr", "MonthlyLastYr") canadaHCD:::station_data[id, vars]
The output shows that this station has no hourly data, but daily and monthly data sets exist.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.