hy_src: Open a connection to the HYDAT database

Description Usage Arguments Value See Also Examples

View source: R/hy_db.R

Description

This function gives low-level access to the underlying HYDAT database used by other functions. Many of these tables are too large to load into memory, so it is best to use dplyr to dplyr::filter() them before using dplyr::collect() to read them into memory.

Usage

1
2
3
hy_src(hydat_path = NULL)

hy_src_disconnect(src)

Arguments

hydat_path

The path to the hydat database or NULL to use the default location used by download_hydat. It is also possible to pass in an existing src_sqlite such that the database only needs to be opened once per user-level call.

src

A as returned by hy_src().

Value

A SQLite DBIConnection

See Also

download_hydat()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
library(dplyr)

# src is a src_sqlite
src <- hy_src(hydat_path = hy_test_db())
src_tbls(src)

# to get a table, use dplyr::tbl()
tbl(src, "STATIONS")

# one you're sure the results are what you want
# get a data.frame using collect()
tbl(src, "STATIONS") %>%
  filter(PROV_TERR_STATE_LOC == "BC") %>%
  collect()
  
# close the connection to the database
hy_src_disconnect(src)

## End(Not run)

ropensci/tidyhydat documentation built on Sept. 20, 2021, 11:50 a.m.