Code Monkey home page Code Monkey logo

weathercan's Introduction

weathercan

:name status badge weathercan status badge R-CMD-check codecov

DOI DOI

This package makes it easier to search for and download multiple months/years of historical weather data from Environment and Climate Change Canada (ECCC) website.

Bear in mind that these downloads can be fairly large and performing multiple downloads may use up ECCC’s bandwidth unnecessarily. Try to stick to what you need.

For more details and tutorials checkout the weathercan website (or see the development docs)

Check out the Demo weathercan shiny dashboard (html; source)

Installation

You can install weathercan from the rOpenSci r-Universe:

install.packages("weathercan", 
                 repos = c("https://ropensci.r-universe.dev", 
                           "https://cloud.r-project.org"))

View the available vignettes with vignette(package = "weathercan")

View a particular vignette with, for example, vignette("weathercan", package = "weathercan")

General usage

To download data, you first need to know the station_id associated with the station you’re interested in.

Stations

weathercan includes the function stations() which returns a list of stations and their details (including station_id).

head(stations())
## # A tibble: 6 × 16
##   prov  station_name        station_id climate_id WMO_id TC_id   lat   lon  elev tz        interval start   end normals normals_1981_2010 normals_1971_2000
##   <chr> <chr>                    <dbl> <chr>       <dbl> <chr> <dbl> <dbl> <dbl> <chr>     <chr>    <dbl> <dbl> <lgl>   <lgl>             <lgl>            
## 1 AB    DAYSLAND                  1795 301AR54        NA <NA>   52.9 -112.  689. Etc/GMT+7 day       1908  1922 FALSE   FALSE             FALSE            
## 2 AB    DAYSLAND                  1795 301AR54        NA <NA>   52.9 -112.  689. Etc/GMT+7 hour        NA    NA FALSE   FALSE             FALSE            
## 3 AB    DAYSLAND                  1795 301AR54        NA <NA>   52.9 -112.  689. Etc/GMT+7 month     1908  1922 FALSE   FALSE             FALSE            
## 4 AB    EDMONTON CORONATION       1796 301BK03        NA <NA>   53.6 -114.  671. Etc/GMT+7 day       1978  1979 FALSE   FALSE             FALSE            
## 5 AB    EDMONTON CORONATION       1796 301BK03        NA <NA>   53.6 -114.  671. Etc/GMT+7 hour        NA    NA FALSE   FALSE             FALSE            
## 6 AB    EDMONTON CORONATION       1796 301BK03        NA <NA>   53.6 -114.  671. Etc/GMT+7 month     1978  1979 FALSE   FALSE             FALSE
glimpse(stations())
## Rows: 26,382
## Columns: 16
## $ prov              <chr> "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", "AB", …
## $ station_name      <chr> "DAYSLAND", "DAYSLAND", "DAYSLAND", "EDMONTON CORONATION", "EDMONTON CORONATION", "EDMONTON CORONATION", "FLEET", "FLEET", "FLEET", …
## $ station_id        <dbl> 1795, 1795, 1795, 1796, 1796, 1796, 1797, 1797, 1797, 1798, 1798, 1798, 1799, 1799, 1799, 1800, 1800, 1800, 1801, 1801, 1801, 1802, …
## $ climate_id        <chr> "301AR54", "301AR54", "301AR54", "301BK03", "301BK03", "301BK03", "301B6L0", "301B6L0", "301B6L0", "301B8LR", "301B8LR", "301B8LR", …
## $ WMO_id            <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ TC_id             <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ lat               <dbl> 52.87, 52.87, 52.87, 53.57, 53.57, 53.57, 52.15, 52.15, 52.15, 53.20, 53.20, 53.20, 52.40, 52.40, 52.40, 54.08, 54.08, 54.08, 53.52,…
## $ lon               <dbl> -112.28, -112.28, -112.28, -113.57, -113.57, -113.57, -111.73, -111.73, -111.73, -110.15, -110.15, -110.15, -115.20, -115.20, -115.2…
## $ elev              <dbl> 688.8, 688.8, 688.8, 670.6, 670.6, 670.6, 838.2, 838.2, 838.2, 640.0, 640.0, 640.0, 1036.0, 1036.0, 1036.0, 585.2, 585.2, 585.2, 668…
## $ tz                <chr> "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "Etc/GMT+7", "E…
## $ interval          <chr> "day", "hour", "month", "day", "hour", "month", "day", "hour", "month", "day", "hour", "month", "day", "hour", "month", "day", "hour…
## $ start             <dbl> 1908, NA, 1908, 1978, NA, 1978, 1987, NA, 1987, 1987, NA, 1987, 1980, NA, 1980, 1980, NA, 1980, 1986, NA, 1986, 1987, NA, 1987, 1986…
## $ end               <dbl> 1922, NA, 1922, 1979, NA, 1979, 1990, NA, 1990, 1998, NA, 1998, 2009, NA, 2007, 1981, NA, 1981, 2019, NA, 2007, 1991, NA, 1991, 1995…
## $ normals           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRU…
## $ normals_1981_2010 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRU…
## $ normals_1971_2000 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…

You can look through this data frame directly, or you can use the stations_search function:

stations_search("Kamloops", interval = "hour")
## # A tibble: 3 × 16
##   prov  station_name station_id climate_id WMO_id TC_id   lat   lon  elev tz        interval start   end normals normals_1981_2010 normals_1971_2000
##   <chr> <chr>             <dbl> <chr>       <dbl> <chr> <dbl> <dbl> <dbl> <chr>     <chr>    <dbl> <dbl> <lgl>   <lgl>             <lgl>            
## 1 BC    KAMLOOPS A         1275 1163780     71887 YKA    50.7 -120.  345. Etc/GMT+8 hour      1953  2013 TRUE    TRUE              TRUE             
## 2 BC    KAMLOOPS A        51423 1163781     71887 YKA    50.7 -120.  345. Etc/GMT+8 hour      2013  2023 FALSE   FALSE             FALSE            
## 3 BC    KAMLOOPS AUT      42203 1163842     71741 ZKA    50.7 -120.  345  Etc/GMT+8 hour      2006  2023 FALSE   FALSE             FALSE

Time frame must be one of “hour”, “day”, or “month”.

You can also search by proximity:

stations_search(coords = c(50.667492, -120.329049), dist = 20, interval = "hour")
## # A tibble: 3 × 17
##   prov  station_name station_id climate_id WMO_id TC_id   lat   lon  elev tz        interval start   end normals normals_1981_2010 normals_1971_2000 distance
##   <chr> <chr>             <dbl> <chr>       <dbl> <chr> <dbl> <dbl> <dbl> <chr>     <chr>    <dbl> <dbl> <lgl>   <lgl>             <lgl>                <dbl>
## 1 BC    KAMLOOPS A         1275 1163780     71887 YKA    50.7 -120.  345. Etc/GMT+8 hour      1953  2013 TRUE    TRUE              TRUE                  8.61
## 2 BC    KAMLOOPS AUT      42203 1163842     71741 ZKA    50.7 -120.  345  Etc/GMT+8 hour      2006  2023 FALSE   FALSE             FALSE                 8.61
## 3 BC    KAMLOOPS A        51423 1163781     71887 YKA    50.7 -120.  345. Etc/GMT+8 hour      2013  2023 FALSE   FALSE             FALSE                 9.26

You can update this list of stations with

stations_dl()
## According to Environment Canada, Modified Date: 2023-01-24 23:30 UTC

## Environment Canada Disclaimers:
## "Station Inventory Disclaimer: Please note that this inventory list is a snapshot of stations on our website as of the modified date, and may be subject to change without notice."
## "Station ID Disclaimer: Station IDs are an internal index numbering system and may be subject to change without notice."

## Stations data saved...
## Use `stations()` to access most recent version and `stations_meta()` to see when this was last updated

And check when it was last updated with

stations_meta()
## $ECCC_modified
## [1] "2023-01-24 23:30:00 UTC"
## 
## $weathercan_modified
## [1] "2023-09-20"

Note: For reproducibility, if you are using the stations list to gather your data, it can be a good idea to take note of the ECCC date of modification and include it in your reports/manuscripts.

Weather

Once you have your station_id(s) you can download weather data:

kam <- weather_dl(station_ids = 51423, start = "2018-02-01", end = "2018-04-15")
## As of weathercan v0.3.0 time display is either local time or UTC
## See Details under ?weather_dl for more information.
## This message is shown once per session
kam
## # A tibble: 1,776 × 37
##    station_name station_id station_operator prov    lat   lon  elev climate_id WMO_id TC_id date       time                year  month day   hour  weather  hmdx
##    <chr>             <dbl> <lgl>            <chr> <dbl> <dbl> <dbl> <chr>      <chr>  <chr> <date>     <dttm>              <chr> <chr> <chr> <chr> <chr>   <dbl>
##  1 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 00:00:00 2018  02    01    00:00 <NA>       NA
##  2 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 01:00:00 2018  02    01    01:00 Snow       NA
##  3 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 02:00:00 2018  02    01    02:00 <NA>       NA
##  4 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 03:00:00 2018  02    01    03:00 <NA>       NA
##  5 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 04:00:00 2018  02    01    04:00 Cloudy     NA
##  6 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 05:00:00 2018  02    01    05:00 <NA>       NA
##  7 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 06:00:00 2018  02    01    06:00 <NA>       NA
##  8 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 07:00:00 2018  02    01    07:00 Cloudy     NA
##  9 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 08:00:00 2018  02    01    08:00 <NA>       NA
## 10 KAMLOOPS A        51423 NA               BC     50.7 -120.  345. 1163781    71887  YKA   2018-02-01 2018-02-01 09:00:00 2018  02    01    09:00 <NA>       NA
## # ℹ 1,766 more rows

You can also download data from multiple stations at once:

kam_pg <- weather_dl(station_ids = c(48248, 51423), start = "2018-02-01", end = "2018-04-15")

Climate Normals

To access climate normals, you first need to know the climate_id associated with the station you’re interested in.

stations_search("Winnipeg", normals_years = "current")
## # A tibble: 1 × 13
##   prov  station_name                station_id climate_id WMO_id TC_id   lat   lon  elev tz        normals normals_1981_2010 normals_1971_2000
##   <chr> <chr>                            <dbl> <chr>       <dbl> <chr> <dbl> <dbl> <dbl> <chr>     <lgl>   <lgl>             <lgl>            
## 1 MB    WINNIPEG RICHARDSON INT'L A       3698 5023222     71852 YWG    49.9 -97.2  239. Etc/GMT+6 TRUE    TRUE              TRUE

Then you can download the climate normals with the normals_dl() function.

n <- normals_dl("5023222")

See the Getting Started vignette for more details.

Citation

citation("weathercan")
## To cite 'weathercan' in publications, please use:
## 
##   LaZerte, Stefanie E and Sam Albers (2018). weathercan: Download and format weather data from Environment and Climate Change Canada. The
##   Journal of Open Source Software 3(22):571. doi:10.21105/joss.00571.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {{weathercan}: {D}ownload and format weather data from Environment and Climate Change Canada},
##     author = {Stefanie E LaZerte and Sam Albers},
##     journal = {The Journal of Open Source Software},
##     volume = {3},
##     number = {22},
##     pages = {571},
##     year = {2018},
##     url = {https://joss.theoj.org/papers/10.21105/joss.00571},
##   }

License

The data and the code in this repository are licensed under multiple licences. All code is licensed GPL-3. All weather data is licensed under the (Open Government License - Canada).

weathercan in the wild!

  • Browse weathercan use cases on rOpenSci.org
  • Checkout the weathercan Shiny App by Nick Rong (@nickyrong) and Nathan Smith (@WraySmith)
  • R package RavenR has functions for converting ECCC data downloaded by weathercan to the .rvt format for Raven.
  • R package meteoland has functions for converting ECCC data downloaded by weathercan to the format required for use in meteoland.

Similar packages

rclimateca

weathercan and rclimateca were developed at roughly the same time and as a result, both present up-to-date methods for accessing and downloading data from ECCC. The largest differences between the two packages are: a) weathercan includes functions for interpolating weather data and directly integrating it into other data sources. b) weathercan actively seeks to apply tidy data principles in R and integrates well with the tidyverse including using tibbles and nested listcols. c) rclimateca contains arguments for specifying short vs. long data formats. d) rclimateca has the option of formatting data in the MUData format using the mudata2 package by the same author.

CHCN

CHCN is an older package last updated in 2012. Unfortunately, ECCC updated their services within the last couple of years which caused a great many of the previous web scrapers to fail. CHCN relies on a decommissioned older web-scraper and so is currently broken.

Contributions

We welcome any and all contributions! To make the process as painless as possible for all involved, please see our guide to contributing

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

ropensci_footer

weathercan's People

Contributors

boshek avatar dependabot[bot] avatar jeroen avatar maelle avatar nicholas512 avatar steffilazerte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weathercan's Issues

Typo in README

There is an unnecessary "is" in the first sentence in the README file.

This package is makes it easier to search for and download multiple months/years of historical weather data from Environment and Climate Change Canada (ECCC) website.

Add listcol functionality

Not for upcoming CRAN submission. I'm uncertain how to ultimately implement this as some user might not like it. Perhaps just as a listcol = TRUE argument in weather().

Need a vignette

In advance of a CRAN submission I think it is prudent to have a good vignette built. The README is basically there but I think we could highlight a few more of the intricacies. Particularly I think we could flesh out the time interval argument explanation. That wasn't immediately obvious to me.

Error in if (tz <= 0) tz <- paste0("+", abs(tz)) else tz <- paste0("-", : argument is of length zero

First of, thank you for creating this package.

Now, about the error: I am trying to run the following code:

library(weathercan)
> kam <- weather_dl(station_ids = 51423, start = "2016-01-01", end = "2016-02-15")
Error in if (tz <= 0) tz <- paste0("+", abs(tz)) else tz <- paste0("-",  : 
  argument is of length zero

Here's the traceback:

Error in if (tz <= 0) tz <- paste0("+", abs(tz)) else tz <- paste0("-", : argument is of length zero
 3. tz_calc(coords = unique(preamble[, c("lat", "lon")]), etc = TRUE)
 2. weather_format(w = w, interval = interval, tz_disp = tz_disp, string_as = string_as, quiet = quiet, preamble = preamble)
 1. weather_dl(station_ids = 51423, start = "2016-01-01", end = "2016-02-15") 

I have tried different station_ids and start & end but get the same error.

CRON jobs for Travis CI

Have Travis CI rebuild the package at intervals to catch any problems that occur if Environment and Climate Change Canada make changes to their side of things.

Add normals data

  • Add climate normals data base
  • Add ability to update climate normals data frame
  • Add function to extract climate normals for a given station? (would pretty much just be a dplyr filter wrapper)
  • ftp://[email protected]/Pub/Normals/English/

OR

Implement a normals calculation

  • Definitely would be faster and would require less bundled data
  • Possibly more prone to errors?

Add progress message

Add progress message to weather_html() under verbose conditions. This will act like a progress indicator for large downloads, so users can see that things are progressing.

Quiet mode and progress bar for weather

  • Need an argument so that weather() doesn't always have output.
  • A progress bar might be useful though I'm not totally clear how that interact with web scraping

Failure when getting date range including 2018-03-31 to 2018-04-01

Expected Behavior

weather_dl() should always return a data frame.

Current Behavior

Sometimes, weather_dl() reports

Error in read.table(file = file, header = header, sep = sep, quote = quote,   : 
more columns than column names

Steps to Reproduce (for bugs)

  1. When extracting data over a date range that includes 2018-03-31 through 2018-04-01, the error is produced. This is not weather-station dependent.

kam <- weather_dl(station_ids = 51423, start = "2018-03-31", end = "2018-04-01")
kam2 <- weather_dl(station_ids=42203, start = "2018-03-31", end = "2018-04-01")
kempt <- weather_dl(station_ids = 27534, start = "2018-03-31", end = "2018-04-01")

Any other date range is ok:
kam <- weather_dl(station_ids = 51423, start = "2018-03-01", end = "2018-03-31")
kam <- weather_dl(station_ids = 51423, start = "2018-04-01", end = "2018-04-30")
kam <- weather_dl(station_ids = 51423, start = "2017-03-31", end = "2017-04-01")

Possible Solution

Comparing the column names of both dates retrieved individually (2018-03-31, 2018-04-01) returns no differences with testthat::expect_equivalent().

Your Environment

Session info -------------------------------------------------------------------------------------------------------------
setting value
version R version 3.5.0 (2018-04-23)
system x86_64, mingw32
ui RStudio (1.1.383)
language (EN)
collate English_Canada.1252
tz America/New_York
date 2018-05-29

Packages -----------------------------------------------------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
base * 3.5.0 2018-04-23 local
bindr 0.1.1 2018-03-13 CRAN (R 3.5.0)
bindrcpp * 0.2.2 2018-03-29 CRAN (R 3.5.0)
compiler 3.5.0 2018-04-23 local
curl 3.2 2018-03-28 CRAN (R 3.5.0)
datasets * 3.5.0 2018-04-23 local
devtools 1.13.5 2018-02-18 CRAN (R 3.5.0)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
dplyr 0.7.5 2018-05-19 CRAN (R 3.5.0)
glue 1.2.0 2017-10-29 CRAN (R 3.5.0)
graphics * 3.5.0 2018-04-23 local
grDevices * 3.5.0 2018-04-23 local
httr 1.3.1 2017-08-20 CRAN (R 3.5.0)
lubridate 1.7.4 2018-04-11 CRAN (R 3.5.0)
magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
methods * 3.5.0 2018-04-23 local
pillar 1.2.1 2018-02-27 CRAN (R 3.5.0)
pkgconfig 2.0.1 2017-03-21 CRAN (R 3.5.0)
purrr 0.2.4 2017-10-18 CRAN (R 3.5.0)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 0.12.16 2018-03-13 CRAN (R 3.5.0)
rlang 0.2.0 2018-02-20 CRAN (R 3.5.0)
stats * 3.5.0 2018-04-23 local
stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.0)
testthat 2.0.0 2017-12-13 CRAN (R 3.5.0)
tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
tidyr 0.8.1 2018-05-18 CRAN (R 3.5.0)
tidyselect 0.2.4 2018-02-26 CRAN (R 3.5.0)
tools 3.5.0 2018-04-23 local
utils * 3.5.0 2018-04-23 local
weathercan * 0.2.6 2018-05-29 Github (3b8d291)
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
xml2 1.2.0 2018-01-24 CRAN (R 3.5.0)
yaml 2.1.18 2018-03-08 CRAN (R 3.5.0)

R version

The R version of weathercan is likely too restrictive. Using this app, shows that we likely only need a version of 3.2.0. Even to be conservative we may considered only requiring 3.3.0 so that older versions of R can run weathercan.

Default to UTC for multiple timezones

Allow the options of converting times to 'relative' time. I.e. if multiple timeszones, force each timezone to UTC (do not convert). This means that 9am in TZ1 corresponds to 9am UTC, also 9am in TZ2 corresponds to 9am UTC. This way daily patterns are directly comparable, but the timezone attribute is a dummy variable.

Package name

I think that we might consider a different package name for a couple reasons:

  • Environment Canada might object to us calling it by their name
  • It isn't totally descriptive of what the package does
  • It doesn't encompass all the other types of environmental monitoring that ec does.

Some other suggestions:

  • canweatheR
  • canadaweatheR
  • canmeteoR

Only import functions we need

From goodpractices::gp(): Do not import packages as a whole, as this can cause name clashes between the imported packages. Instead, import only the specific functions you need.

PR on rclimateca

Hi, lots of duplication on the 'rclimateca' package. Haven't updated it for a while given PhD school constraints, but feel free to PR missing features that are available here that are not currently available in rclimateca. Cheers!

Update example in flags vignette

The flags vignette makes a reference to a "missing data" flag, which is no longer present. Choose a new example and update the vignette.

Download multiple years but only certain months

This is a problem and short-term solution reported by John Lewis.

Question: Is it possible to selectively download only winter months across multiple stations and multiple years?
Answer: It is possible in the future to implement that for hourly data, but it is currently not implemented (and won't be immediately implemented)

John presented this work-around in the meantime:

library("weathercan")
library("tidyverse")
stations_search("Ottawa", interval = "hour")

#example of downloading data for specific time period(s) during a year
#in this case it is for 4 years of winter hourly data for Ottawa
st <- c("2011-12-14","2012-11-01","2013-11-01","2014-11-01")
ed <-c("2012-03-31","2013-03-31","2014-03-31","2015-03-31")
otta <- vector("list", length(st))
for (i in seq_along(st)){
    otta[[i]] <- weather_dl(station_id=49568,start = st[[i]],
       end = ed[[i]])
}

otta

##########################
#View(out)
#if you want to combine the data into one large data frame you can
#save the output in a list, then use dplyr::bind_rows(output) to
#combine the output into a single data frame.
ott <- dplyr::bind_rows(otta)
head(ott)
tail(ott)

Any way to refresh `stations` dataframe?

Hi,

I recently discovered your extremely useful package. Thank you for creating it!

I was wondering how often the stations dataframe is updated, since I noticed a discrepancy between it and weather.gc.ca. It's annoying how weather stations stop reporting/change on the website from time to time, but is there a way to get a refresh of the list so we can manually fix any scripts whenever a change occurs?

Thanks!

Daily downloads missing dates in the second year

Expected Behaviour

weather_dl(station_id = 49568, interval = "day", start = "2012-11-01", end = "2013-04-05")

Should return daily data from 2012-11-01 to 2013-04-05

Current Behaviour

Data is truncated at 2012-12-31

Memoise download functions

We should consider adding a memoise ability to any download function.

This cache's the output in a session so that unless the parameters have changed, identical download calls will only be downloaded once per session. It is fairly easy to implement and can provide a reasonable buffer to repeated identical downloads.

Here is the memoise package: https://github.com/r-lib/memoise

Check tests for CRAN

Check tests and make sure that they're CRAN friendly, if not, add skip on CRAN

Add French localisation

Look into adding French as a language option for messages, errors, and, possibly, documentation.

Env Canada station location precision

I was wondering if there is any way to got lat/lon coordinates at a higher precision than 2 decimal places, which is an error of plus or minus 1.1km or less.

Thank you, this package has proven invaluable to our research team.

J

weather_dl throws error ` 'names' attribute [25] must be the same length as the vector [24]`

Expected Behavior

weather_dl should return weather data

Current Behavior

weather_dl errors out

Steps to Reproduce (for bugs)

Using GitHub PAT from envvar GITHUB_PAT
Downloading GitHub repo ropensci/weathercan@master
from URL https://api.github.com/repos/ropensci/weathercan/zipball/master
Installing weathercan
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save  \
  --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/48/q6ltldjs251000_wvjrdy_vm0000gn/T/Rtmp2j8c0e/devtoolse0ba9742238/ropensci-weathercan-0eafb91'  \
  --library='/Library/Frameworks/R.framework/Versions/3.5/Resources/library' --install-tests 

* installing *source* package ‘weathercan’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (weathercan)
> library(weathercan)
> kam.pg <- weather_dl(station_ids = c(48248, 51423),
+                       start = "2016-01-01", end = "2016-02-15")
Error in names(w) <- n : 
  'names' attribute [25] must be the same length as the vector [24]

Your Environment

> devtools::session_info()
Session info -----------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.0 (2018-04-23)
 system   x86_64, darwin15.6.0        
 ui       RStudio (1.1.442)           
 language (EN)                        
 collate  en_CA.UTF-8                 
 tz       America/Vancouver           
 date     2018-05-10                  

Packages ---------------------------------------------------------------------------------------
 package    * version date       source                              
 assertthat   0.2.0   2017-04-11 CRAN (R 3.5.0)                      
 base       * 3.5.0   2018-04-24 local                               
 bindr        0.1.1   2018-03-13 CRAN (R 3.5.0)                      
 bindrcpp   * 0.2.2   2018-03-29 CRAN (R 3.5.0)                      
 compiler     3.5.0   2018-04-24 local                               
 curl         3.2     2018-03-28 CRAN (R 3.5.0)                      
 datasets   * 3.5.0   2018-04-24 local                               
 devtools     1.13.5  2018-02-18 CRAN (R 3.5.0)                      
 digest       0.6.15  2018-01-28 CRAN (R 3.5.0)                      
 dplyr        0.7.4   2017-09-28 CRAN (R 3.5.0)                      
 git2r        0.21.0  2018-01-04 CRAN (R 3.5.0)                      
 glue         1.2.0   2017-10-29 CRAN (R 3.5.0)                      
 graphics   * 3.5.0   2018-04-24 local                               
 grDevices  * 3.5.0   2018-04-24 local                               
 httr         1.3.1   2017-08-20 CRAN (R 3.5.0)                      
 knitr        1.20    2018-02-20 CRAN (R 3.5.0)                      
 lubridate    1.7.4   2018-04-11 CRAN (R 3.5.0)                      
 magrittr     1.5     2014-11-22 CRAN (R 3.5.0)                      
 memoise      1.1.0   2017-04-21 CRAN (R 3.5.0)                      
 methods    * 3.5.0   2018-04-24 local                               
 pillar       1.2.2   2018-04-26 CRAN (R 3.5.0)                      
 pkgconfig    2.0.1   2017-03-21 CRAN (R 3.5.0)                      
 purrr        0.2.4   2017-10-18 CRAN (R 3.5.0)                      
 R6           2.2.2   2017-06-17 CRAN (R 3.5.0)                      
 Rcpp         0.12.16 2018-03-13 CRAN (R 3.5.0)                      
 rlang        0.2.0   2018-02-20 CRAN (R 3.5.0)                      
 stats      * 3.5.0   2018-04-24 local                               
 stringi      1.2.2   2018-05-02 CRAN (R 3.5.0)                      
 stringr      1.3.0   2018-02-19 CRAN (R 3.5.0)                      
 tibble       1.4.2   2018-01-22 CRAN (R 3.5.0)                      
 tidyr        0.8.0   2018-01-29 CRAN (R 3.5.0)                      
 tidyselect   0.2.4   2018-02-26 CRAN (R 3.5.0)                      
 tools        3.5.0   2018-04-24 local                               
 utils      * 3.5.0   2018-04-24 local                               
 weathercan * 0.2.5   2018-05-10 Github (ropensci/weathercan@0eafb91)
 withr        2.1.2   2018-03-15 CRAN (R 3.5.0)                      
 yaml         2.1.19  2018-05-01 CRAN (R 3.5.0)    

dplyr 0.70

I think we should test this with all the changes in dplyr 0.70 especially the tidyeval programming stuff. And I think we should do this ahead of a cran submission. Of course this means learning all that new stuff but it probably has to happen at some point anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.