Skip to content

Commit f481024

Browse files
committed
v0.2.4
1 parent e7b0a43 commit f481024

File tree

13 files changed

+228
-73
lines changed

13 files changed

+228
-73
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: tidyhydat
22
Title: Extract tidy hydrometric data
3-
Version: 0.2.3
3+
Version: 0.2.4
44
Authors@R: c(person("Sam", "Albers", email = "sam.albers@gov.bc.ca", role = c("aut", "cre"),
55
), person("Dave", "Hutchinson", email = "david.hutchinson@canada.ca", role = "ctb"))
66
Description: tidyhydat provides functions to extract river data from Water Survey of Canada sources and make it tidy.

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(STN_OPERATION_SCHEDULE)
1818
export(STN_REGULATION)
1919
export(STN_REMARKS)
2020
export(VERSION)
21+
export(download_hydat)
2122
export(download_realtime_dd)
2223
export(download_realtime_ws)
2324
export(get_ws_token)
@@ -35,3 +36,5 @@ importFrom(lubridate,year)
3536
importFrom(lubridate,ymd)
3637
importFrom(tibble,tibble)
3738
importFrom(tidyr,gather)
39+
importFrom(utils,download.file)
40+
importFrom(utils,unzip)

NEWS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
#tidyhydat 0.2.4
2+
* download_realtime_ws can now accept stations from multiple provinces or simply select multiple provinces
3+
* better error messages for get_ws_token and download_realtime_ws
4+
* All functions that previously accepted STATION_NUMBER == "ALL" now throw an error.
5+
* Added function to download hydat
6+
17
#tidyhydat 0.2.3
28
* Remove significant redundancy in station selecting mechanism
39
* Added package startup message when HYDAT is out of date
410
* Add internal allstations data
511
* Added all the tables as functions or data from HYDAT
6-
* Made missing station ouput truncated at 10 missign stations
12+
* Made missing station ouput truncated at 10 missing stations
713

814
# tidyhdyat 0.2.2
915
* Adding several new tables

R/tidyhydat.R

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#' @importFrom lubridate year
3131
#' @importFrom lubridate month
3232
#' @importFrom lubridate day
33+
#' @importFrom utils download.file
34+
#' @importFrom utils unzip
3335
#' @import readr
3436
#' @import dplyr
3537
#' @import httr
@@ -47,29 +49,3 @@
4749
#'
4850
NULL
4951

50-
51-
#' REmoves notes from R CMD check for NSE
52-
#'
53-
.onLoad <- function(libname = find.package("tidyhydat"), pkgname = "tidyhydat"){
54-
# CRAN Note avoidance
55-
if(getRversion() >= "2.15.1")
56-
utils::globalVariables(
57-
# Vars used in Non-Standard Evaluations, declare here to avoid CRAN warnings
58-
## This is getting ridiculous
59-
c("PROV_TERR_STATE_LOC", "FULL_MONTH", "MAX", "DAY", "FLOW", "MONTH",
60-
"YEAR", "Date","stns", "FLOW", "LEVEL","PRECISION_CODE","NO_DAYS",
61-
"variable","temp","DATA_SYMBOLS","FLOW_SYMBOL","SYMBOL_EN","Value",
62-
"Unit","Grade","Symbol","Approval","Parameter","Code","param_id","Name_En",
63-
"Name_Fr","LEVEL_SYMBOL","ID","val","key","CODE","GRADE","SYMBOL",
64-
"DATA_TYPE","DATA_TYPES","DATA_TYPE_EN","MAX_DAY","MAX_MONTH","MAX_SYMBOL","MEAN",
65-
"MIN","MIN_DAY","MIN_MONTH","MIN_SYMBOL","SUM_STAT","HOUR", "MINUTE", "PEAK",
66-
"PEAK_CODE", "REGIONAL_OFFICE_ID","TIME_ZONE","SUSCON", "CONCENTRATION","CONCENTRATION_EN",
67-
"CONVERSION_FACTOR", "DATE", "DATUM_EN","DATUM_EN_FROM", "DATUM_EN_TO", "LOAD", "MEASUREMENT_EN",
68-
"MONTH_FROM", "MONTH_TO", "OPERATION_EN", "PARTICLE_SIZE", "PERCENT", "REMARK_EN", "REMARK_TYPE_EN",
69-
"SAMPLER_TYPE", "SAMPLE_REMARK_EN", "SAMPLING_VERTICAL_EN", "SAMPLING_VERTICAL_LOCATION", "SED_DATA_TYPE_EN",
70-
"SV_DEPTH2", "TEMPERATURE", "TIME_SYMBOL", "YEAR_FROM", "YEAR_TO",
71-
"." # piping requires '.' at times
72-
)
73-
)
74-
invisible()
75-
}

R/zzz.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@
2525
#
2626
#
2727
#}
28+
29+
#' Removes notes from R CMD check for NSE
30+
#'
31+
.onLoad <- function(libname = find.package("tidyhydat"), pkgname = "tidyhydat"){
32+
# CRAN Note avoidance
33+
if(getRversion() >= "2.15.1")
34+
utils::globalVariables(
35+
# Vars used in Non-Standard Evaluations, declare here to avoid CRAN warnings
36+
## This is getting ridiculous
37+
c("PROV_TERR_STATE_LOC", "FULL_MONTH", "MAX", "DAY", "FLOW", "MONTH",
38+
"YEAR", "Date","stns", "FLOW", "LEVEL","PRECISION_CODE","NO_DAYS",
39+
"variable","temp","DATA_SYMBOLS","FLOW_SYMBOL","SYMBOL_EN","Value",
40+
"Unit","Grade","Symbol","Approval","Parameter","Code","param_id","Name_En",
41+
"Name_Fr","LEVEL_SYMBOL","ID","val","key","CODE","GRADE","SYMBOL",
42+
"DATA_TYPE","DATA_TYPES","DATA_TYPE_EN","MAX_DAY","MAX_MONTH","MAX_SYMBOL","MEAN",
43+
"MIN","MIN_DAY","MIN_MONTH","MIN_SYMBOL","SUM_STAT","HOUR", "MINUTE", "PEAK",
44+
"PEAK_CODE", "REGIONAL_OFFICE_ID","TIME_ZONE","SUSCON", "CONCENTRATION","CONCENTRATION_EN",
45+
"CONVERSION_FACTOR", "DATE", "DATUM_EN","DATUM_EN_FROM", "DATUM_EN_TO", "LOAD", "MEASUREMENT_EN",
46+
"MONTH_FROM", "MONTH_TO", "OPERATION_EN", "PARTICLE_SIZE", "PERCENT", "REMARK_EN", "REMARK_TYPE_EN",
47+
"SAMPLER_TYPE", "SAMPLE_REMARK_EN", "SAMPLING_VERTICAL_EN", "SAMPLING_VERTICAL_LOCATION", "SED_DATA_TYPE_EN",
48+
"SV_DEPTH2", "TEMPERATURE", "TIME_SYMBOL", "YEAR_FROM", "YEAR_TO","condensed_date",
49+
"." # piping requires '.' at times
50+
)
51+
)
52+
invisible()
53+
}

README.Rmd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ To use most of the `tidyhydat` package you will need the most recent version of
4747

4848
- http://collaboration.cmc.ec.gc.ca/cmc/hydrometrics/www/
4949

50+
`tidyhydat` also provides a convenience function to download hydat (be patient though this takes a long time!):
51+
```{r, eval=FALSE}
52+
download_hydat(hydat_path = "H:/")
53+
```
54+
5055
You will need to download that file, unzip it and put it somewhere on local storage. The path to the sqlite3 must be specified within each function that uses HYDAT. If the path is very long it may be useful to store it as an object with a smaller name like this:
5156
```{r eval = FALSE}
5257
hydat_loc = "A very long path that points to the HYDAT sqlite3 database"
@@ -64,6 +69,7 @@ It is important that you name the variable `hydat` as that is name of the variab
6469

6570
## Usage
6671

72+
### HYDAT
6773
This is a basic example of `tidyhydat` usage. All functions that interact with HYDAT are capitalized (e.g. `STATIONS`). These functions follow a common argument structure which can be illustrated with the `DLY_FLOWS()` function. If you would like to extract only station `08LA001` you can supply the `STATION_NUMBER`. The `hydat_path` argument is supplied here as a local path the database. Yours will be different or missing altogether if you set the variable in your `.Renviron` file which is highly recommend.
6874

6975
```{r example1, warning=FALSE}
@@ -81,6 +87,18 @@ You can also make use of auxiliary function in `tidyhdyat` called `search_name`
8187
search_name("liard")
8288
```
8389

90+
### Real-time
91+
To download real-time data using the datamart we can use approximately the same conventions discussed above. Using `download_realtime_dd()` we can easily select specific stations by supplying a station of interest:
92+
```{r}
93+
download_realtime_dd(STATION_NUMBER = "08LG006")
94+
```
95+
Another option is to provide simply the province as an argument and download all stations from that province:
96+
```{r}
97+
download_realtime_dd(PROV_TERR_STATE_LOC = "PE")
98+
```
99+
Additionally `download_realtime_ws()` provides another means of acquiring real time data.
100+
101+
84102
## Project Status
85103

86104
This package is under continual development.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ To use most of the `tidyhydat` package you will need the most recent version of
3737

3838
- <http://collaboration.cmc.ec.gc.ca/cmc/hydrometrics/www/>
3939

40+
`tidyhydat` also provides a convenience function to download hydat (be patient though this takes a long time!):
41+
42+
``` r
43+
download_hydat(hydat_path = "H:/")
44+
```
45+
4046
You will need to download that file, unzip it and put it somewhere on local storage. The path to the sqlite3 must be specified within each function that uses HYDAT. If the path is very long it may be useful to store it as an object with a smaller name like this:
4147

4248
``` r
@@ -60,6 +66,8 @@ It is important that you name the variable `hydat` as that is name of the variab
6066
Usage
6167
-----
6268

69+
### HYDAT
70+
6371
This is a basic example of `tidyhydat` usage. All functions that interact with HYDAT are capitalized (e.g. `STATIONS`). These functions follow a common argument structure which can be illustrated with the `DLY_FLOWS()` function. If you would like to extract only station `08LA001` you can supply the `STATION_NUMBER`. The `hydat_path` argument is supplied here as a local path the database. Yours will be different or missing altogether if you set the variable in your `.Renviron` file which is highly recommend.
6472

6573
``` r
@@ -117,6 +125,52 @@ search_name("liard")
117125
#> 3 10BE006 LIARD RIVER ABOVE KECHIKA RIVER
118126
```
119127

128+
### Real-time
129+
130+
To download real-time data using the datamart we can use approximately the same conventions discussed above. Using `download_realtime_dd()` we can easily select specific stations by supplying a station of interest:
131+
132+
``` r
133+
download_realtime_dd(STATION_NUMBER = "08LG006")
134+
#> # A tibble: 17,508 x 8
135+
#> STATION_NUMBER PROV_TERR_STATE_LOC Date Parameter Value
136+
#> <chr> <chr> <dttm> <chr> <dbl>
137+
#> 1 08LG006 BC 2017-07-30 08:00:00 FLOW 7.41
138+
#> 2 08LG006 BC 2017-07-30 08:05:00 FLOW 7.41
139+
#> 3 08LG006 BC 2017-07-30 08:10:00 FLOW 7.41
140+
#> 4 08LG006 BC 2017-07-30 08:15:00 FLOW 7.38
141+
#> 5 08LG006 BC 2017-07-30 08:20:00 FLOW 7.38
142+
#> 6 08LG006 BC 2017-07-30 08:25:00 FLOW 7.38
143+
#> 7 08LG006 BC 2017-07-30 08:30:00 FLOW 7.38
144+
#> 8 08LG006 BC 2017-07-30 08:35:00 FLOW 7.38
145+
#> 9 08LG006 BC 2017-07-30 08:40:00 FLOW 7.38
146+
#> 10 08LG006 BC 2017-07-30 08:45:00 FLOW 7.38
147+
#> # ... with 17,498 more rows, and 3 more variables: Grade <chr>,
148+
#> # Symbol <chr>, Code <chr>
149+
```
150+
151+
Another option is to provide simply the province as an argument and download all stations from that province:
152+
153+
``` r
154+
download_realtime_dd(PROV_TERR_STATE_LOC = "PE")
155+
#> # A tibble: 77,824 x 8
156+
#> STATION_NUMBER PROV_TERR_STATE_LOC Date Parameter Value
157+
#> <chr> <chr> <dttm> <chr> <dbl>
158+
#> 1 01CD005 PE 2017-07-30 04:00:00 FLOW NA
159+
#> 2 01CD005 PE 2017-07-30 04:05:00 FLOW NA
160+
#> 3 01CD005 PE 2017-07-30 04:10:00 FLOW NA
161+
#> 4 01CD005 PE 2017-07-30 04:15:00 FLOW NA
162+
#> 5 01CD005 PE 2017-07-30 04:20:00 FLOW NA
163+
#> 6 01CD005 PE 2017-07-30 04:25:00 FLOW NA
164+
#> 7 01CD005 PE 2017-07-30 04:30:00 FLOW NA
165+
#> 8 01CD005 PE 2017-07-30 04:35:00 FLOW NA
166+
#> 9 01CD005 PE 2017-07-30 04:40:00 FLOW NA
167+
#> 10 01CD005 PE 2017-07-30 04:45:00 FLOW NA
168+
#> # ... with 77,814 more rows, and 3 more variables: Grade <chr>,
169+
#> # Symbol <chr>, Code <chr>
170+
```
171+
172+
Additionally `download_realtime_ws()` provides another means of acquiring real time data.
173+
120174
Project Status
121175
--------------
122176

inst/doc/tidyhydat.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ DLY_FLOWS(hydat_path = "H:/Hydat.sqlite3",
3232
start_date = "1992-03-15",
3333
end_date = "1992-04-15")
3434

35+
## ---- eval=FALSE---------------------------------------------------------
36+
# download_hydat(hydat_path = "H:/")
37+
3538
## ------------------------------------------------------------------------
3639
VERSION(hydat_path = "H:/Hydat.sqlite3")
3740

@@ -87,5 +90,8 @@ param_id
8790
# WS_PWD = "here is the password that ECCC gave you"
8891

8992
## ------------------------------------------------------------------------
90-
download_realtime_dd(STATION_NUMBER = "08LG006", PROV_TERR_STATE_LOC = "BC")
93+
download_realtime_dd(STATION_NUMBER = "08LG006")
94+
95+
## ------------------------------------------------------------------------
96+
download_realtime_dd(PROV_TERR_STATE_LOC = "PE")
9197

inst/doc/tidyhydat.Rmd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ All functions that interact with HYDAT are capitalized (e.g. `STATIONS`). To use
8989

9090
- http://collaboration.cmc.ec.gc.ca/cmc/hydrometrics/www/
9191

92+
`tidyhydat` also provides a convenience function to download hydat (be patient though this takes a long time!):
93+
```{r, eval=FALSE}
94+
download_hydat(hydat_path = "H:/")
95+
```
96+
9297
You can check your version of HYDAT with the `VERSION()` function:
9398
```{r}
9499
VERSION(hydat_path = "H:/Hydat.sqlite3")
@@ -192,11 +197,14 @@ WS_PWD = "here is the password that ECCC gave you"
192197
Now these values can be accessed within an R session without giving away your secrets (Using `Sys.getenv()`). Just remember to call them directly and don't assign them to a variable.
193198

194199
## MSC datamart - `download_realtime_dd()`
195-
To download real-time data using the datamart we can use approximately the same conventions discussed above. Using `download_realtime_dd()` we can easily select specific stations by supplying a station of interest. Note that in contrast to `download_realtime_ws()` but similar to `DLY_FLOWS()`, we need to supply both the station and the province that we are interested in:
200+
To download real-time data using the datamart we can use approximately the same conventions discussed above. Using `download_realtime_dd()` we can easily select specific stations by supplying a station of interest:
196201
```{r}
197-
download_realtime_dd(STATION_NUMBER = "08LG006", PROV_TERR_STATE_LOC = "BC")
202+
download_realtime_dd(STATION_NUMBER = "08LG006")
203+
```
204+
Another option is to provide simply the province as an argument and download all stations from that province:
205+
```{r}
206+
download_realtime_dd(PROV_TERR_STATE_LOC = "PE")
198207
```
199-
200208

201209
## Compare `download_realtime_ws` and `download_realtime_dd`
202210
`tidyhydat` provides two methods to download real-time data. `download_realtime_ws()`, coupled with `get_ws_token()`, is an API client for a web service hosted by ECCC. `download_realtime_dd()` provides a function to import openly accessible .csv files from [here](http://dd.weather.gc.ca/hydrometric/). `download_realtime_ws()` has several difference to `download_realtime_dd()`. These include:

0 commit comments

Comments
 (0)