ipeaGIT / geobr

Easy access to official spatial data sets of Brazil in R and Python
https://ipeagit.github.io/geobr/
786 stars 118 forks source link

read_municipality() does not work for 2001: Error in data.table::rbindlist(files, fill = TRUE): Class attribute on column 5 of item 28 does not match with column 5 of item 1. #274

Closed MatthieuStigler closed 2 years ago

MatthieuStigler commented 2 years ago

Hi

Thanks for the nice package! It seems that there is a problem with geobr::read_municipality(year = 2001, simplified = TRUE), but just for year 2001? Other years in [2000, 2020] seemed fine! Is it possible this year has less columns?

Thanks!

This happens with version 1.6.5

check_server_ok <- geobr::download_metadata()
#> Loading required namespace: sf
geobr::read_municipality(year = 2001, simplified = TRUE)
#> Using year 2001
#> Loading data for the whole country. This might take a few minutes.
#> Error in data.table::rbindlist(files, fill = TRUE): Class attribute on column 5 of item 28 does not match with column 5 of item 1.

Created on 2022-02-08 by the reprex package (v2.0.1)

rafapereirabr commented 2 years ago

Thanks for the heads up. The number of columns are the same. It seems there is a conflic the class of column five. I'll fix this in the next round of updates / fixes.

In the meantime, I would suggest you donwload the data for anther year. If, however, you need to use 2001 data, this code here is a way around this issue:

library(geobr)
library(sf)
library(data.table)

# download states
states <- read_state(year=2001)

# separately download the municipities of each state
munis_list <- lapply( X = states$abbrev_state,
                      FUN = function(i) { read_municipality(code_muni = i, year = 2001) }
                     )

# rbind all municipalities
munis <- rbindlist(munis_list)

# back to sf
munis <- st_sf(munis)
MatthieuStigler commented 2 years ago

thanks for your quick answer, and for suggesting a workaround!

rafapereirabr commented 2 years ago

Hi @MatthieuStigler . This issue has now been fixed. No need to reinstall geobr. Simply restart your R session and it should work fine. Please let me know if the problem persists. Closing this issue for now

MatthieuStigler commented 2 years ago

Nice, I can confirm it is working, thanks!

I notice geobr::download_metadata() doesn't work anymore... is that on purpose?

rafapereirabr commented 2 years ago

download_metadata() is intended as an internal function and it is not exported anymore. If case you really need to use it, you can run geobr:::download_metadata() , with three :::.

If you would like to know all datasets available in the geobr package, you can use the list_geobr() function.

ps. I do not recommend using download_metadata(). As of today, geobr downloads data sets from two two separate servers. If one server fails, geobr automatically downloads the data from the second server. However, this does not work if you manually use the url links in the metadata table.