You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another method is to use `hy_stations()` to generate your vector which is then given the `station_number` argument. For example, we could take a subset for only those active stations within Prince Edward Island (Province code:PE) and then create vector for `hy_daily_flows()`:
We can also merge our station choice and data extraction into one unified pipe which accomplishes a single goal. For example if for some reason we wanted all the stations in Canada that had the name "Canada" in them we unify that selection and data extraction process into a single pipe:
## Queried from version of HYDAT released on 2022-10-24
125
-
## Observations: 86,147
126
-
## Measurement flags: 26,222
124
+
## Queried from version of HYDAT released on 2023-11-20
125
+
## Observations: 87,669
126
+
## Measurement flags: 26,754
127
127
## Parameter(s): Flow
128
-
## Date range: 1918-08-01 to 2022-06-30
128
+
## Date range: 1918-08-01 to 2023-05-31
129
129
## Station(s) returned: 7
130
130
## Stations requested but not returned:
131
131
## All stations returned.
132
-
## # A tibble: 86,147 × 5
132
+
## # A tibble: 87,669 × 5
133
133
## STATION_NUMBER Date Parameter Value Symbol
134
134
## <chr> <date> <chr> <dbl> <chr>
135
135
## 1 01AK001 1918-08-01 Flow NA <NA>
@@ -142,7 +142,7 @@ search_stn_name("canada") %>%
142
142
## 8 01AK001 1918-08-08 Flow 1.78 <NA>
143
143
## 9 01AK001 1918-08-09 Flow 1.5 <NA>
144
144
## 10 01AK001 1918-08-10 Flow 1.78 <NA>
145
-
## # … with 86,137 more rows
145
+
## # ℹ 87,659 more rows
146
146
```
147
147
148
148
We saw above that if we were only interested in a subset of dates we could use the `start_date` and `end_date` arguments. A date must be supplied to both these arguments in the form of YYYY-MM-DD. If you were interested in all daily flow data from station number "08LA001" for 1981, you would specify all days in 1981 :
@@ -196,18 +196,18 @@ search_stn_name("liard")
196
196
197
197
```
198
198
## # A tibble: 9 × 5
199
-
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE LONGIT…¹
200
-
## <chr> <chr> <chr> <dbl> <dbl>
201
-
## 1 10AA001 LIARD RIVER AT UPPER CROSSING YT 60.1 -129.
202
-
## 2 10AA006 LIARD RIVER BELOW SCURVY CREEK YT 60.8 -131.
203
-
## 3 10BE001 LIARD RIVER AT LOWER CROSSING BC 59.4 -126.
204
-
## 4 10ED001 LIARD RIVER AT FORT LIARD NT 60.2 -123.
205
-
## 5 10ED002 LIARD RIVER NEAR THE MOUTH NT 61.7 -121.
206
-
## 6 10BE005 LIARD RIVER ABOVE BEAVER RIVER BC 59.7 -124.
207
-
## 7 10BE006 LIARD RIVER ABOVE KECHIKA RIVER BC 59.7 -127.
208
-
## 8 10ED008 LIARD RIVER AT LINDBERG LANDING NT 61.1 -123.
209
-
## 9 10GC004 MACKENZIE RIVER ABOVE LIARD RIVER NT 61.9 -121.
210
-
## # … with abbreviated variable name ¹LONGITUDE
199
+
## STATION_NUMBER STATION_NAME PROV_TERR_STATE_LOC LATITUDE
200
+
## <chr> <chr> <chr> <dbl>
201
+
## 1 10AA001 LIARD RIVER A… YT 60.1
202
+
## 2 10AA006 LIARD RIVER B… YT 60.8
203
+
## 3 10BE001 LIARD RIVER A… BC 59.4
204
+
## 4 10ED001 LIARD RIVER A… NT 60.2
205
+
## 5 10ED002 LIARD RIVER N… NT 61.7
206
+
## 6 10BE005 LIARD RIVER A… BC 59.7
207
+
## 7 10BE006 LIARD RIVER A… BC 59.7
208
+
## 8 10ED008 LIARD RIVER A… NT 61.1
209
+
## 9 10GC004 MACKENZIE RIV… NT 61.9
210
+
## # ℹ 1 more variable: LONGITUDE <dbl>
211
211
```
212
212
Similarly, `search_stn_number()` can be useful if you are interested in all stations from the *08MF* sub-sub-drainage:
Our objective here is to filter from this data for the station that has the longest record of flow (`DATA_TYPE == "Q"`). You'll also notice this symbol `%>%` which in R is called a [pipe](https://magrittr.tidyverse.org/reference/pipe.html). In code, read it as the word *then*. So for the data_range data we want to grab the data *then* filter it by flow ("Q") in `DATA_TYPE` and then by the maximum value of `RECORD_LENGTH`:
84
85
@@ -88,15 +89,16 @@ hy_stn_data_range() %>%
88
89
```
89
90
90
91
```
91
-
## Queried from version of HYDAT released on 2022-10-24
92
+
## Queried from version of HYDAT released on 2023-11-20
Working with SQL tables in dplyr is much like working with regular data frames, except no data is actually read from the database until necessary. Because some of these tables are large (particularly those containing the actual data), you will want to `filter()` the tables before you `collect()` them (the `collect()` operation loads them into memory as a `data.frame`).
When you are finished with the database (i.e., the end of the script), it is good practice to close the connection (you may get a loud red warning if you don't!).
0 commit comments