% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/datasus_catalog.R
\name{datasus_get_territory}
\alias{datasus_get_territory}
\title{Download DATASUS territorial tables}
\usage{
datasus_get_territory(
  table = "tb_municip",
  year = NULL,
  format = "csv",
  cache_dir = NULL,
  verbose = TRUE
)
}
\arguments{
\item{table}{Name of the table to read. Common values:
\code{"tb_municip"} (municipalities), \code{"tb_uf"} (states),
\code{"tb_regsaud"} (health regions), \code{"tb_macsaud"} (macro health regions),
\code{"tb_regiao"} (geographic regions), \code{"tb_micibge"} (IBGE micro-regions),
\code{"tb_regmetr"} (metropolitan regions), \code{"tb_dsei"} (indigenous health
districts). Relationship tables start with \code{"rl_"} (e.g.
\code{"rl_municip_regsaud"}).}

\item{year}{Year of the territorial table. Defaults to the current year.
Use \code{datasus_ftp_ls("ftp://ftp.datasus.gov.br/territorio/tabelas/")}
to see available years.}

\item{format}{File format to extract from the ZIP: \code{"csv"} (default) or
\code{"dbf"}.}

\item{cache_dir}{Optional cache directory.}

\item{verbose}{Logical. Emit progress messages (default \code{TRUE}).}
}
\value{
A tibble with column names in snake_case.
}
\description{
Downloads and reads tables from the DATASUS territorial data section.
The DATASUS FTP publishes a ZIP archive per year containing reference
tables for municipalities, health regions, and other geographic
divisions used by SUS, in CSV, DBF, and TXT formats.
}
\examples{
\donttest{
tryCatch({
  # Download territorial tables into tempdir() (network required).
  municipios <- datasus_get_territory(
    "tb_municip",
    cache_dir = tempdir(),
    verbose   = FALSE
  )
  ufs <- datasus_get_territory(
    "tb_uf",
    cache_dir = tempdir(),
    verbose   = FALSE
  )
}, error = function(e) message("FTP unavailable: ", conditionMessage(e)))
}
}
