brazil_municipality_code()
returns a vector with codes of the Brazilian
Institute of Geography and Statistics (IBGE) for
Brazilian municipalities.
Note: This function requires an active internet connection and the
geobr
package to be installed.
Usage
brazil_municipality_code(
municipality,
state = NULL,
year = as.numeric(substr(Sys.Date(), 1, 4)),
names = TRUE,
...
)
Arguments
- municipality
(optional) A
character
vector with the name of the municipalities. IfNULL
the function returns all municipalities (default:NULL
).- state
(optional) A
character
vector with the name of the states (default:NULL
).- year
(optional) An
integerish
number indicating the year of the data regarding the municipalities (default:Sys.Date() |> substr(1, 4) |> as.numeric()
).- names
(optional) A
logical
flag indicating whether to return the names of the municipalities as names of the vector (default:TRUE
).- ...
(optional) Additional arguments passed to
brazil_municipality()
.
Value
An integer
vector with the IBGE codes of
Brazilian municipalities.
Details
The data from this function is based on data from the Brazilian Institute
of Geography and Statistics (IBGE) via the
geobr
R package.
The geobr
package is produced by Brazil's Institute for
Applied Economic Research (IPEA) and access the
Brazilian Institute of Geography and Statistics
(IBGE) data. You can see a list of all
geobr
datasets by running
geobr::list_geobr()
.
See also
Other Brazil functions:
brazil_fu()
,
brazil_municipality()
,
brazil_municipality_coords()
,
brazil_municipality_latitude()
,
brazil_municipality_longitude()
,
brazil_region()
,
brazil_region_code()
,
brazil_render_address()
,
brazil_state()
,
brazil_state_by_utc()
,
brazil_state_capital()
,
brazil_state_code()
,
brazil_state_latitude()
,
brazil_state_longitude()
Examples
library(curl)
# \dontrun{
if (has_internet()) {
brazil_municipality_code(municipality = "Belém")
}
#> Belém-PA Belém-PB Belém-AL
#> 1501402 2501906 2700805
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_code(municipality = "Belém", names = FALSE)
}
#> [1] 1501402 2501906 2700805
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_code(municipality = "Belém", state = "Pará")
}
#> Belém-PA
#> 1501402
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_code(c("Rio de Janeiro", "São Paulo"))
}
#> Rio de Janeiro-RJ São Paulo-SP
#> 3304557 3550308
# }