Intelligently fetches data or metadata based on the identifier(s) provided. Works with dataset names, dataset IDs, resource IDs, or tibbles from po_catalog/po_search.
Arguments
- identifier
Dataset name, dataset ID, resource ID(s), or tibble of resources
- what
What to get: "data" (default), "info", or "all"
- format
Preferred format when multiple are available (e.g., "CSV", "XLSX")
- clean_names
Logical. Clean column names for R compatibility (default TRUE)
- save_to
Directory path to save downloaded files (default NULL = no saving)
- encoding
Character encoding: "UTF-8" (default), "Latin1", "Windows-1252", "ISO-8859-1", or "auto"
- use_cache
Logical. Use cached files if available (default TRUE)
- verbose
Logical. Show download progress (default TRUE)
Value
Depending on input:
- Single resource
A data.frame/tibble or metadata depending on 'what'
- Multiple resources
A named list of data/metadata for each resource
- Dataset
Data/metadata from the best available resource
Examples
if (FALSE) { # \dontrun{
# Get data using dataset name
malaria <- po_get("malaria-2024")
# Get metadata only
info <- po_get("malaria-2024", what = "info")
# Get specific resource by ID
data <- po_get("abc-123-resource-id")
# Get multiple resources
resources <- po_get(c("resource-id-1", "resource-id-2"))
# Get resources from catalog/search results
catalog <- po_catalog()
csv_resources <- catalog$resources %>% filter(format == "CSV")
all_csv_data <- po_get(csv_resources)
# Save files locally with original names
data <- po_get("dataset-name", save_to = "data/peru/")
# Force specific encoding for Spanish characters
data <- po_get("resource-id", encoding = "Windows-1252")
data <- po_get("resource-id", encoding = "ISO-8859-1")
# Cache control examples
data <- po_get("resource-id") # Uses cache if available
data <- po_get("resource-id", use_cache = FALSE) # Force fresh download
} # }
