summaryrefslogtreecommitdiffstats
path: root/man/cep_lookup_many.Rd
blob: 9362649ffc14f8a5ca30ea83b6b07d5d6d50cedd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/api.R
\name{cep_lookup_many}
\alias{cep_lookup_many}
\title{Look up many CEPs in one request}
\usage{
cep_lookup_many(ceps, client = default_client())
}
\arguments{
\item{ceps}{A character vector of CEPs, masked or unmasked.}

\item{client}{A \code{\link[=cepis_client]{cepis_client()}}. Defaults to a shared client built with
the default configuration.}
}
\value{
A list of \strong{the same length and in the same order} as \code{ceps}.
Each element is a \link{cepis_address}, or \code{NULL} where the CEP does not
exist or is malformed — it does not vanish from the list, and it does not
signal a condition. That is the right difference from \code{\link[=cep_lookup]{cep_lookup()}}: in
a batch of a thousand, one bad CEP must not cost the other nine hundred
and ninety-nine. Use \code{\link[=normalize_cep]{normalize_cep()}} beforehand if you need to know
\emph{which} input was malformed.

A list rather than a \code{data.frame} because \code{NULL} is the only unambiguous
"no such CEP" in R: a row of \code{NA}s reads as an address with unknown
fields, which is a different statement, and an empty row cannot be told
apart from a CEP the database knows only by number. Rectangle it with
\code{do.call(rbind, lapply(result, function(a) as.data.frame(a[1:13])))} when
a \code{data.frame} is what you want.
}
\description{
Resolves up to 500 CEPs per request, chunking longer inputs automatically.
Do not loop over \code{\link[=cep_lookup]{cep_lookup()}}: a loop of 500 calls pays 500 TLS
handshakes, the batch pays one.
}
\section{Batches carry no coordinate}{

The endpoint behind them is CSV, and the CSV has no \code{geo} column. Every
address returned here has \code{geo = NULL}, including for CEPs that do have
one. Need \code{geo}? Use \code{\link[=cep_lookup]{cep_lookup()}}, one at a time.
}

\examples{
\donttest{
ceps <- c("01001000", "99999999", "20040020")
result <- cep_lookup_many(ceps)
vapply(result, function(a) if (is.null(a)) NA_character_ else a$localidade,
       character(1))
}

}