tests/testthat/test-read_statistical_grid.R

context("read_statistical_grid")

# skip tests because they take too much time
testthat::skip_on_cran()
skip_if(Sys.getenv("TEST_ONE") != "")


test_that("read_statistical_grid", {

  temp <- read_statistical_grid(year=2010, code_muni="all", output = "arrow")
  testthat::expect_true( nrow(temp) == 13286535 )

  temp <- read_statistical_grid(year=2010, code_muni="AC", output = "arrow")
  testthat::expect_true( nrow(temp) == 183695 )

  temp <- read_statistical_grid(year=2010, code_muni=2927408, output = "arrow")
  testthat::expect_true( nrow(temp) == 17254 )

  testthat::expect_true(is(temp, "ArrowObject"))


  temp <- read_statistical_grid(year=2010, code_muni=2927408, output = "duckdb")
  testthat::expect_true(is(temp, "duckspatial_df"))

  temp <- read_statistical_grid(year=2010, code_muni=2927408, output = "sf")

  testthat::expect_true("sf"  %in% class(temp))


  })



# ERRORS
test_that("read_statistical_grid", {

  # Wrong year and code
  testthat::expect_error(read_statistical_grid())
  testthat::expect_error(read_statistical_grid(code_muni=NULL))

  # Wrong code
  testthat::expect_error(read_statistical_grid(code_muni=9999999))

  # Wrong year
  testthat::expect_error(read_statistical_grid(code_muni="AC"))
  testthat::expect_error(read_statistical_grid( year=9999999))

  # Wrong output
  testthat::expect_error(
    read_statistical_grid(year=2022, code_muni="AC", output = "banana")
    )

})

Try the geobr package in your browser

Any scripts or data that you put into this service are public.

geobr documentation built on June 23, 2026, 5:06 p.m.