Skip to contents

get_closest_geobr_year() returns the closest year available in the geobr package for a specified type of data.

Usage

get_closest_geobr_year(year, type = "country", verbose = TRUE)

Arguments

year

An integerish vector with the year to find the closest available year in the geobr package.

type

(optional) A string indicating the type of data to find the closest year for. It can be one of the following: "municipality", "municipal_seat", "state", or "country" (default: "country").

verbose

(optional) A logical flag indicating whether to print a warning message if the specified year is not available in the geobr package. Only applicable if year is a single value (default: TRUE).

Value

A numeric vector with the closest year available in the geobr package for the specified type of data.

See also

Other utility functions: fix_postal_code(), get_map_fill_data()

Examples

get_closest_geobr_year(2025, type = "municipality")
#> ! The closest map year to 2025 is 2022. Using year 2022 instead.
#> [1] 2022
#> [1] 2022 # Expected

get_closest_geobr_year(2025, type = "state")
#> ! The closest map year to 2025 is 2020. Using year 2020 instead.
#> [1] 2020
#> [1] 2020 # Expected

get_closest_geobr_year(2025, type = "country")
#> ! The closest map year to 2025 is 2020. Using year 2020 instead.
#> [1] 2020
#> [1] 2020 # Expected

get_closest_geobr_year(c(2025, 1999, NA, 1800), type = "country")
#> [1] 2020 2000   NA 1872
#> [1] 2020 2000   NA 1872 # Expected