Check if a product is a data-bearing leaf or an empty container
Source:R/products.R
product_has_data.RdThe Trafa API does not model parent-child relationships between products
explicitly. However, some products (e.g. "Fordon på väg", t10010) have
dimensions and measures in their structure but return no data rows — they
act as organizational containers. This function checks whether a product
has actual data by inspecting its structure for dimension/measure items
whose parent_name matches the product code, and then verifying whether
the data endpoint returns rows.
Usage
product_has_data(
product,
lang = NULL,
cache = FALSE,
cache_location = trafa_cache_dir,
verbose = FALSE
)Value
Logical: TRUE if the product's data endpoint returns rows,
FALSE if it appears to be an empty container.
Details
Note: when a product is a container, the related "sub-products"
cannot be discovered programmatically via the API. Use
product_search() on the product catalogue to find products with
similar names (e.g. product_search(get_products(), "fordon")).
Examples
# \donttest{
if (trafa_available()) {
product_has_data("t10011") # TRUE — Bussar has data
product_has_data("t10010") # FALSE — container, no data rows
}# }
#> Warning: No data rows in Trafa API response.
#> [1] FALSE