Skip to contents

Loads a Household Travel Survey (HTS) table from POPS database, local cache, or CSV file. Converts ID columns to character for consistency.

Usage

fetch_hts_table(
  table,
  settings,
  columns = "*",
  local_path = NULL,
  replace = FALSE
)

Arguments

table

character. Database table name (e.g., 'ex_hh', 't_admin').

settings

list. Must include:

  • pops_dir — POPS directory

  • dbname — database name

  • schema — database schema Additional settings as needed for table retrieval

columns

character. Columns to fetch. Default: all columns ('*').

local_path

character. Path to CSV file to load. Optional.

replace

logical. If TRUE, replaces cached table. Default FALSE.

Value

data.table with columns:

  • household_id — household identifier

  • person_id — person identifier

  • trip_id — trip identifier

  • Additional columns for requested variables and attributes (type varies) Rows: one per record. Keys: (household_id, person_id, trip_id) as applicable.

Details

  • Loads from cache if available and replace = FALSE.

  • Otherwise, fetches from POPS database or CSV file.

  • Converts *_id columns to character for reliable joins.

  • Saves to cache after fetching.

  • Returns a copy; does not modify by reference.

Settings

  • pops_dir (direct): POPS directory. Default from settings.

  • dbname (direct): Database name. Default from settings.

  • schema (direct): Database schema. Default from settings.

Examples

## Not run:
settings <- list(pops_dir = "pops", dbname = "hts", schema = "public")
dt <- fetch_hts_table('ex_hh', settings)
#> Error in fetch_hts_table("ex_hh", settings): Parent folder does not exist. Did you run load_settings()?
## End(Not run)