Skip to contents

inspercidados gives R users direct access to datasets from Insper Cidades, hosted on Insper Dataverse. Insper Cidades is a multidisciplinary research center at Insper. The package wraps dataverse so you can find, download, and cite datasets in a few short commands.

Installation

The stable version of the package is available on CRAN.

install.packages("inspercidados")

The development version of the package is available on R-universe.

install.packages(
  "inspercidados",
  repos = c(
    "https://inspercidades.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Core functions

Function Purpose
list_datasets() List or search available datasets
list_resources() List logical resources within a dataset
get_dataset() Download a dataset into R
query_dataset() Query a parquet dataset without loading it into R
get_dataverse() Inspect or download any Insper Dataverse deposit
cite_dataset() Generate a citation for a dataset
open_project() Open the study repository behind a dataset

Browse available datasets

list_datasets() returns a tibble of every dataset in the registry. The registry is read from GitHub once per session, so datasets added after a release appear without reinstalling. Offline, the package uses the copy it shipped with.

library(inspercidados)

list_datasets()
#> # A tibble: 23 × 11
#>    alias        title description theme region project access is_spatial formats
#>    <chr>        <chr> <chr>       <chr> <chr>  <chr>   <chr>  <lgl>      <chr>  
#>  1 itbi_sp      Impo… "Registros… Habi… São P… itbi    downl… FALSE      csv, p…
#>  2 iptu_sp      IPTU… "Dados do … Habi… São P… densid… downl… TRUE       geojso…
#>  3 alvaras_sp   Alva… "Informaçõ… Habi… São P… alvaras downl… TRUE       geojso…
#>  4 alvaras_sp_… Alva… "Agregação… Habi… São P… alvaras downl… TRUE       geojso…
#>  5 censo_setor… Popu… "Dados pro… Habi… São P… densid… downl… TRUE       geojso…
#>  6 iptu_vertic… Grad… "Dados dem… Habi… São P… densid… downl… TRUE       geojso…
#>  7 densidade_i… Dens… "Cruzament… Habi… São P… densid… downl… TRUE       geojso…
#>  8 geoses_sp    Índi… "Índice so… Mult… São P… geoses  downl… TRUE       geojso…
#>  9 mortalidade… Indi… "Indicador… Saúde São P… mortal… downl… TRUE       geojso…
#> 10 ilhas_calor… Medi… "Estatísti… Clim… Rio d… mare    downl… TRUE       geojso…
#> # ℹ 13 more rows
#> # ℹ 2 more variables: keywords <chr>, doi <chr>

Search by alias, title, description, theme, region, or keywords.

list_datasets("Mobilidade")
#> # A tibble: 12 × 11
#>    alias        title description theme region project access is_spatial formats
#>    <chr>        <chr> <chr>       <chr> <chr>  <chr>   <chr>  <lgl>      <chr>  
#>  1 geoses_sp    Índi… Índice soc… Mult… São P… geoses  downl… TRUE       geojso…
#>  2 pemob_anual  Pesq… Base anual… Mobi… Brasil pemob   downl… FALSE      parque…
#>  3 pemob_harmo… Pesq… Base anual… Mobi… Brasil pemob   downl… FALSE      parque…
#>  4 embarques_h… Emba… Embarques … Mobi… Brasil motiva  downl… FALSE      csv, p…
#>  5 embarques_d… Emba… Total de e… Mobi… Brasil motiva  downl… FALSE      parque…
#>  6 embarques_m… Médi… Média de e… Mobi… Brasil motiva  downl… FALSE      rds, t…
#>  7 embarques_i… Emba… Embarques … Mobi… Brasil motiva  downl… FALSE      parque…
#>  8 linhas_moti… Linh… Tabela de … Mobi… Brasil motiva  downl… FALSE      rds, t…
#>  9 estacoes_mo… Linh… Tabela de … Mobi… Brasil motiva  downl… FALSE      rds, t…
#> 10 faixa_azul_… Trec… Localizaçã… Mobi… São P… faixa_… downl… TRUE       geojso…
#> 11 sinistros_sp Sini… Sinistros … Mobi… São P… faixa_… downl… FALSE      parque…
#> 12 sinistros_v… Sini… Localizaçã… Mobi… São P… faixa_… downl… TRUE       geojso…
#> # ℹ 2 more variables: keywords <chr>, doi <chr>

The Alvarás study has two separate deposits: 2004–2021 is alvaras_sp_2004_2021, and 2010–2024 is alvaras_sp. Both are available through get_dataset().

Download a dataset

Pass a short alias to download a registered dataset.

# By alias
embarques <- get_dataset("embarques_mensais")

# Filter by year in multi-year datasets
pemob_2023 <- get_dataset("pemob_anual", year = 2023)

# Select a logical resource and format
pontos <- get_dataset(
  "qualidade_ar_mare",
  resource = "pontos",
  format = "gpkg"
)

list_resources() shows the logical datasets and formats inside a registered deposit.

list_resources("qualidade_ar_mare")
#> # A tibble: 2 × 6
#>   resource title                                is_spatial years formats default
#>   <chr>    <chr>                                <lgl>      <chr> <chr>   <lgl>  
#> 1 dados    Medições de qualidade do ar          FALSE      <NA>  parque… TRUE   
#> 2 pontos   Pontos das medições de qualidade do… TRUE       <NA>  geojso… FALSE

Set docs = TRUE to return the data alongside its documentation. For datasets with a dictionary workbook, docs contains that workbook.

result <- get_dataset("iptu_sp", docs = TRUE)
result$data
result$docs

Query a large dataset

query_dataset() opens a registered parquet resource as a lazy table. Build a query with dplyr, then call collect() to bring the result into R. This needs the optional duckdb, DBI, dbplyr, and dplyr packages.

itbi <- query_dataset("itbi_sp")

itbi |>
  dplyr::select(data_de_transacao) |>
  head(5) |>
  dplyr::collect()

For resources split into annual files, year selects one year. With no year, the query includes all available years.

Cite a dataset

cite_dataset() fetches metadata from Dataverse and returns a citation in plain text, BibTeX, or RIS.

cite_dataset("embarques_mensais")
cite_dataset("embarques_mensais", format = "bibtex")
cite_dataset("embarques_mensais", format = "ris")

Explore the study behind a dataset

Most datasets come from a research study whose pipeline lives in its own repository. open_project() prints the study, lists its datasets, and opens the repository.

open_project("faixa_azul")

Learn more

To learn more about the package, check https://inspercidades.github.io/inspercidados/