Skip to contents

A set of functions to build a lookup cache, add new tables to it, and retrieve cached data. The cache is used to store lookup tables for species, age classes, survey types, and other related data.

Usage

build_cache()

add_cache_tables(api, endpoint)

get_cached_data(table, filter_fn = NULL, api = NULL, endpoint = NULL)

Arguments

api

API endpoint to fetch data from

endpoint

Endpoint to fetch data from

table

Name of table to retrieve

filter_fn

Optional function to filter the data

Value

  • build_cache() invisibly returns a named list of tibbles. Keys include: species, project_species, age_classes, management_units, analysis_units, analysis_unit_versions, and parameters. Additional keys may be present depending on the API response.

  • get_cached_data() returns a tibble. If filter_fn reduces results to zero rows, a 0-row tibble with the same columns is returned. Aborts if the requested table is not found in the cache.

  • add_cache_tables() invisibly returns the entire cache (a named list of all tibbles, not just the newly added ones).

Examples

if (FALSE) { # \dontrun{
# Build the cache
build_cache()

# Add counts lookup tables to cache
add_cache_tables("counts", "/lookup-counts")

# Get data from cache
get_cached_data("species")

} # }