% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/datasus_catalog.R
\name{datasus_fetch}
\alias{datasus_fetch}
\title{Fetch DATASUS data in one step}
\usage{
datasus_fetch(
  source,
  file_type,
  year = NULL,
  month = NULL,
  uf = NULL,
  ...,
  bind = TRUE,
  include_prelim = TRUE,
  timeout = 240,
  use_cache = TRUE,
  cache_dir = NULL,
  verbose = TRUE
)
}
\arguments{
\item{source}{Character vector of source codes.}

\item{file_type}{Character vector of file type codes.}

\item{year}{Integer vector of years.}

\item{month}{Integer vector of months (required for monthly sources).}

\item{uf}{Character vector of UF codes (required for UF-scoped sources).}

\item{...}{Additional arguments forwarded to \code{\link[=read_datasus_dbc]{read_datasus_dbc()}} (e.g.
\code{select}, \code{col_types}, \code{parse_dates}).}

\item{bind}{Logical. When \code{TRUE} (the default), all files are row-bound into
a single tibble. When \code{FALSE}, a list of tibbles is returned.}

\item{include_prelim}{Logical. Include preliminary data trees (default \code{TRUE}).}

\item{timeout}{Timeout in seconds for FTP and download operations
(default 240).}

\item{use_cache}{Logical. Reuse cached downloads (default \code{TRUE}).}

\item{cache_dir}{Optional cache directory.}

\item{verbose}{Logical. Emit progress messages (default \code{TRUE}).}
}
\value{
A tibble (when \code{bind = TRUE}) or a named list of tibbles.
}
\description{
A convenience wrapper that lists, downloads, and reads DATASUS files in a
single call. Particularly useful for interactive / exploratory work.
}
\examples{
\donttest{
tryCatch({
  # Fetch a small SIHSUS slice into tempdir() (network required).
  df <- datasus_fetch(
    source    = "SIHSUS",
    file_type = "RD",
    year      = 2024,
    month     = 1,
    uf        = "AC",
    select    = c("uf_zi", "ano_cmpt", "munic_res", "val_tot"),
    cache_dir = tempdir(),
    verbose   = FALSE
  )
}, error = function(e) message("FTP unavailable: ", conditionMessage(e)))
}
}
