Load HTS table from POPS, cache, or CSV
fetch_hts_table.RdLoads a Household Travel Survey (HTS) table from POPS database, local cache, or CSV file. Converts ID columns to character for consistency.
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.
See also
fetch_from_db,fix_value_labels_on_loadscripts/io/fetch_hts_table.R
Other io utilities:
clean_data_dict(),
cut_and_label(),
db_table_has_geometry(),
fetch_acs(),
fetch_all_hts_tables(),
fetch_from_db(),
fetch_pums(),
fetch_study_region(),
find_project_root(),
fix_value_labels_on_load(),
get_db_table_name(),
print_params(),
pums_checksum(),
read_from_db(),
read_pums_codebook(),
record_checksum(),
sampled_latlon_to_bg()
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)