### cache_dir() example with output Source: https://docs.ropensci.org/weathercan/reference/cache_dir.html Example call to cache_dir() showing the default cache directory path. ```r cache_dir() #> [1] "~/.local/share/weathercan" ``` -------------------------------- ### Example: stations_meta() with check_eccc() Source: https://docs.ropensci.org/weathercan/reference/stations_meta.html Example usage of stations_meta() wrapped in a check_eccc() call, which is only run when the check_eccc() condition is true. The example is wrapped in an if (FALSE) block, indicating it is not run by default. ```r if (FALSE) { # check_eccc() stations_meta() } ``` -------------------------------- ### normals_file example output Source: https://docs.ropensci.org/weathercan/reference/normals_file.html Example call to normals_file() and its output, showing the expected file path for the cached normals data. ```r normals_file() #> [1] "~/.local/share/weathercan/1991-2020_Canadian_Climate_Normals_CANADA_Data.csv" ``` -------------------------------- ### stations_search() examples Source: https://docs.ropensci.org/weathercan/reference/stations_search.html Example calls to stations_search() demonstrating name searches, interval filtering, year range restrictions, normals_years options, and coordinate-based search. The examples are wrapped in if (FALSE) { # check_eccc() } to prevent execution during package checks. ```r if (FALSE) { # check_eccc() stations_search(name = "Kamloops") stations_search(name = "Kamloops", interval = "hour") stations_search(name = "Ottawa", starts_latest = 1950, ends_earliest = 2010) stations_search(name = "Ottawa", normals_years = "current") # 1981-2010 stations_search(name = "Ottawa", normals_years = "1981-2010") # Same as above stations_search(name = "Ottawa", normals_years = "1971-2000") # 1971-2010 if(requireNamespace("sf")) { stations_search(coords = c(53.915495, -122.739379)) } } ``` -------------------------------- ### Install weathercan from r-Universe Source: https://docs.ropensci.org/weathercan/index.html Install the weathercan package from the rOpenSci r-Universe repository. Use this before loading the package for the first time. ```r install.packages( "weathercan", repos = c("https://ropensci.r-universe.dev", "https://cloud.r-project.org") ) ``` -------------------------------- ### Example: Interpolate weather data for finch observations Source: https://docs.ropensci.org/weathercan/reference/weather_interp.html Example from the documentation (wrapped in if (FALSE) to avoid execution). It shows how to align timezones between finch observation times and weather data, then calls weather_interp to interpolate weather for the first 30 observations. The example assumes data frames 'kamloops' and 'finches' are already loaded. ```r if (FALSE) { # check_eccc() # Weather data only kamloops # Data about finch observations at RFID feeders in Kamloops, BC finches # Match weather to finches # First line up the timezones # - Finches are in Pacific Time (inc. Daylight savings), # Kamloops is in Pacific Time *without* daylight savings, but is marked as UTC for # simplicity (see ?weather_dl for details) # - First we convert finches to remove daylight savings, then we mark as UTC finches <- dplyr::mutate(finches, time = lubridate::with_tz(time, "Etc/GMT+8")) finches <- dplyr::mutate(finches, time = lubridate::force_tz(time, "UTC")) # Then interpolate over the first 30 observations finch_weather <- weather_interp(data = finches[1:30,], weather = kamloops) } ``` -------------------------------- ### weather_dl and stations_search example Source: https://docs.ropensci.org/weathercan/reference/weather_dl.html Example R code wrapped in if (FALSE) to prevent execution. It downloads weather data for Kamloops and Prince George, searches for stations, and plots temperature over time. Also shows downloading only January and December data using the months parameter. ```R if (FALSE) { # check_eccc() kam <- weather_dl(station_ids = 51423, start = "2016-01-01", end = "2016-02-15") stations_search("Kamloops A$", interval = "hour") stations_search("Prince George Airport", interval = "hour") kam.pg <- weather_dl(station_ids = c(48248, 51423), start = "2016-01-01", end = "2016-02-15") library(ggplot2) ggplot(data = kam.pg, aes(x = time, y = temp, group = station_name, colour = station_name)) + geom_line() # Download only January and December kam <- weather_dl( station_ids = 51423, start = "2016-01-01", end = "2018-02-15", months = c(1, 10) ) } ``` -------------------------------- ### Example output of check_eccc() returning FALSE Source: https://docs.ropensci.org/weathercan/reference/check_eccc.html Example output of check_eccc() when the checks fail, returning FALSE. ```r check_eccc() #> [1] FALSE ``` -------------------------------- ### Sample output of stations() Source: https://docs.ropensci.org/weathercan/articles/weathercan.html Example tibble output from stations() showing station metadata columns such as prov, station_name, station_id, and normals flags. ```r ## # A tibble: 6 × 17 ## prov station_name station_id climate_id WMO_id TC_id lat lon elev tz interval start end normals normals_1991_2020 normals_1981_2010 ## ## 1 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 hour NA NA FALSE FALSE FALSE ## 2 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 day 1908 1922 FALSE FALSE FALSE ## 3 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 month 1908 1922 FALSE FALSE FALSE ## 4 AB EDMONTON CORONATION 1796 301BK03 NA 53.6 -114. 671. Etc/GMT+7 hour NA NA FALSE FALSE FALSE ``` -------------------------------- ### Load required packages for downloading normals Source: https://docs.ropensci.org/weathercan/articles/normals.html Loads weathercan for downloading data, tidyr for unnesting, dplyr for data manipulation, and naniar for exploring missing values. This setup is needed before using normals_dl() and stations_search(). ```R library(weathercan) library(tidyr) library(dplyr) library(naniar) # For exploring missing values ``` -------------------------------- ### Output of head(stations()) Source: https://docs.ropensci.org/weathercan/index.html Example output from head(stations()) showing the first six rows of the station data frame. The output includes columns such as prov, station_name, station_id, climate_id, and interval. ```r ## # A tibble: 6 × 17 ## prov station_name station_id climate_id WMO_id TC_id lat lon elev tz interval start end normals normals_1991_2020 normals_1981_2010 ## ## 1 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 hour NA NA FALSE FALSE FALSE ## 2 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 day 1908 1922 FALSE FALSE FALSE ## 3 AB DAYSLAND 1795 301AR54 NA 52.9 -112. 689. Etc/GMT+7 month 1908 1922 FALSE FALSE FALSE ## 4 AB EDMONTON CORONATION 1796 301BK03 NA 53.6 -114. 671. Etc/GMT+7 hour NA NA FALSE FALSE FALSE ## 5 AB EDMONTON CORONATION 1796 301BK03 NA 53.6 -114. 671. Etc/GMT+7 day 1978 1979 FALSE FALSE FALSE ## 6 AB EDMONTON CORONATION 1796 301BK03 NA 53.6 -114. 671. Etc/GMT+7 month 1978 1979 FALSE FALSE FALSE ## # ℹ 1 more variable: normals_1971_2000 ``` -------------------------------- ### Download multiple stations weather with weather_dl() Source: https://docs.ropensci.org/weathercan/index.html Downloads weather data for multiple stations at once by passing a vector of station IDs to `weather_dl()`. The example uses stations 48248 and 51423 for the same date range. ```r kam_pg <- weather_dl( station_ids = c(48248, 51423), start = "2018-02-01", end = "2018-04-15" ) ``` -------------------------------- ### Download multiple climate IDs for composite stations Source: https://docs.ropensci.org/weathercan/reference/normals_dl.html Download climate normals for multiple climate IDs that form a composite station (e.g., for 1990-2010 normals). The example shows how to view the composite_stations column. ```R stations_search("Winnipeg", normals_years = "current") n <- normals_dl(climate_ids = c("502S001", "5023227", "5023222")) unique(dplyr::select(n, "location_name", "composite_stations")) ``` -------------------------------- ### Load required libraries for weathercan Source: https://docs.ropensci.org/weathercan/articles/weathercan.html Loads dplyr, ggplot2, and weathercan packages needed for the examples in this article. ```r library(dplyr) library(ggplot2) library(weathercan) ``` -------------------------------- ### cache_remove() example in interactive session Source: https://docs.ropensci.org/weathercan/reference/cache_remove.html Example usage of cache_remove() wrapped in an if (FALSE) block to prevent execution during package checks. It is intended for interactive use. ```r if (FALSE) { # interactive() cache_remove() } ``` -------------------------------- ### Terminal notice for weathercan program Source: https://docs.ropensci.org/weathercan/LICENSE.html Output this notice when the program starts in interactive mode. It includes the copyright line and warranty/redistribution conditions, with commands 'show w' and 'show c' to display the relevant license parts. ```plaintext weathercan Copyright (C) 2019 Steffi LaZerte This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Download 1981-2010 normals for a climate ID Source: https://docs.ropensci.org/weathercan/articles/normals.html Use normals_dl with climate_ids and normals_years to download normals data for a specific station. The example downloads normals for climate ID 5023222 and assigns the result to n. ```R n <- normals_dl(climate_ids = "5023222", normals_years = "1981-2010") n ``` -------------------------------- ### stations() Source: https://docs.ropensci.org/weathercan/reference/stations.html Returns the built-in stations data frame containing station metadata from Environment and Climate Change Canada. The data frame includes columns for province, station name, station ID, climate ID, WMO ID, TC ID, latitude, longitude, elevation, timezone, interval, start and end years, and climate normals availability. ```APIDOC ## stations() ### Description Returns the built-in stations data frame containing station metadata from Environment and Climate Change Canada. The data frame includes columns for province, station name, station ID, climate ID, WMO ID, TC ID, latitude, longitude, elevation, timezone, interval, start and end years, and climate normals availability. ### Usage ```r stations() ``` ### Format A data frame with the following columns: - **prov** (character) - Province - **station_name** (character) - Station name - **station_id** (numeric) - Environment Canada's station ID number. Required for downloading station data. - **climate_id** (character) - Climate ID number - **WMO_id** (character) - Climate ID number - **TC_id** (character) - Climate ID number - **lat** (numeric) - Latitude of station location in degree decimal format - **lon** (numeric) - Longitude of station location in degree decimal format - **elev** (numeric) - Elevation of station location in metres - **tz** (character) - Local timezone excluding any Daylight Savings - **interval** (character) - Interval of the data measurements ('hour', 'day', 'month') - **start** (numeric) - Starting year of data record - **end** (numeric) - Ending year of data record - **normals** (logical) - Whether _any_ climate normals are available for that station (new behaviour) - **normals_1991_2020** (logical) - Whether 1991-2020 climate normals are available for that station. **Note** that even if available, these are not yet downloadable via weathercan. - **normals_1981_2010** (logical) - Whether 1981-2010 climate normals are available for that station - **normals_1971_2000** (logical) - Whether 1971-2000 climate normals are available for that station ### Details You can check when this was last updated with `stations_meta()`. A dataset containing station information downloaded from Environment and Climate Change Canada. Note that a station may have several station IDs, depending on how the data collection has changed over the years. Station information can be updated by running `stations_dl()`. ### Examples ```r if (FALSE) { # check_eccc() stations() stations_meta() # Which Manitoba stations have *any* climate normals? # Note `normals` is TRUE or FALSE, so we can included it as is for normals == TRUE library(dplyr) filter(stations(), interval == "hour", normals, prov == "MB") } ``` ``` -------------------------------- ### Download weather data with weather_dl() Source: https://docs.ropensci.org/weathercan/articles/tidyhydat.html Downloads daily weather data for station 50821 (Brandon) for the date range specified by dates[1] and dates[2]. The interval is set to 'day'. ```R rain <- weather_dl( station_ids = 50821, interval = "day", start = dates[1], end = dates[2] ) ``` -------------------------------- ### cache_dir() usage Source: https://docs.ropensci.org/weathercan/reference/cache_dir.html Usage of the cache_dir() function to get the cache directory path. ```r cache_dir() ``` -------------------------------- ### Reproducibility workflow with weathercan Source: https://docs.ropensci.org/weathercan/articles/reproducibility.html Run this R code to download weather data and then capture the stations metadata, package citation, and session info for reproducibility. Requires the devtools package for session_info(). ```R # Work library(weathercan) s <- stations_search("Winnipeg", normals_years = "current") w <- weather_dl(s, interval = "month", start = "2021-01-01") # Reproducibility stations_meta() citation('weathercan') devtools::session_info() # Install devtools if you don't have it ``` -------------------------------- ### Download weather data with weather_dl() Source: https://docs.ropensci.org/weathercan/articles/weathercan.html Downloads weather data for station 51423 from 2016-01-01 to 2016-02-15. ```r kam <- weather_dl(station_ids = 51423, start = "2016-01-01", end = "2016-02-15") ``` -------------------------------- ### Load required packages Source: https://docs.ropensci.org/weathercan/articles/tidyhydat.html Loads weathercan, tidyhydat, and supporting packages (dplyr, ggplot2, lubridate, glue) for the workflow. ```r library(weathercan) library(tidyhydat) library(dplyr) library(ggplot2) library(lubridate) library(glue) ``` -------------------------------- ### Download single station weather with weather_dl() Source: https://docs.ropensci.org/weathercan/index.html Downloads weather data for a single station using `weather_dl()`. The output includes a message about time display (shown once per session) and a tibble with 1,776 rows and 38 columns, including station metadata and hourly observations. ```r kam <- weather_dl(station_ids = 51423, start = "2018-02-01", end = "2018-04-15") ``` ```r ## As of weathercan v0.3.0 time display is either local time or UTC See Details under `weather_dl()` (`?weather_dl()`) for more information. This message is shown ## once per session ``` ```r kam ``` ```r ## # A tibble: 1,776 × 38 ## station_name station_id station_operator prov lat lon elev climate_id WMO_id TC_id date time year month day hour qual temp ##