Problem
frs_network() returns sf objects to R memory. All downstream pipeline functions (frs_col_join, frs_col_generate, frs_break, frs_classify, frs_aggregate) operate on DB tables. This forces a round-trip through R between the network query and the pipeline — at province scale (multiple watershed groups), materializing all geometries in R blows up memory.
Proposed Solution
Add to parameter. When provided, write results to DB tables instead of returning sf:
# Current: pulls to R (unchanged, to=NULL default)
result <- frs_network(conn, blk, drm, tables = list(streams = "..."))
# New: stays on DB, returns conn for piping
conn |>
frs_network(blk, drm, to = "working.byman", tables = list(
streams = "whse_basemapping.fwa_stream_networks_sp",
lakes = "whse_basemapping.fwa_lakes_poly")) |>
frs_col_join("working.byman_streams", ...) |>
frs_col_generate("working.byman_streams") |>
frs_break("working.byman_streams", ...) |>
frs_classify("working.byman_streams", ...)
Multi-table naming
to is a prefix. Table list names become suffixes:
to = "working.byman" + streams → working.byman_streams
to = "working.byman" + lakes → working.byman_lakes
- Single table:
to used as-is (no suffix)
Internal changes
frs_network_direct() and frs_network_waterbody() get to param
- When
to is NULL: frs_db_query() → returns sf (current)
- When
to is provided: .frs_db_execute("CREATE TABLE AS") → returns NULL
- SQL body identical — only execution path changes
overwrite param (default TRUE) for DROP IF EXISTS
- Error if
clip and to both provided (clip is R-side spatial op)
Blast radius
All existing callers use to=NULL (default) — zero breakage:
- fresh tests (35+), vignettes (4), breaks app_server.R, restoration scripts (3)
Only data-raw/example_byman_ailport.R and the new habitat pipeline vignette will use to=.
Problem
frs_network()returns sf objects to R memory. All downstream pipeline functions (frs_col_join,frs_col_generate,frs_break,frs_classify,frs_aggregate) operate on DB tables. This forces a round-trip through R between the network query and the pipeline — at province scale (multiple watershed groups), materializing all geometries in R blows up memory.Proposed Solution
Add
toparameter. When provided, write results to DB tables instead of returning sf:Multi-table naming
tois a prefix. Table list names become suffixes:to = "working.byman"+streams→working.byman_streamsto = "working.byman"+lakes→working.byman_lakestoused as-is (no suffix)Internal changes
frs_network_direct()andfrs_network_waterbody()gettoparamtois NULL:frs_db_query()→ returns sf (current)tois provided:.frs_db_execute("CREATE TABLE AS")→ returns NULLoverwriteparam (default TRUE) for DROP IF EXISTSclipandtoboth provided (clip is R-side spatial op)Blast radius
All existing callers use
to=NULL(default) — zero breakage:Only
data-raw/example_byman_ailport.Rand the new habitat pipeline vignette will useto=.