Skip to content

Commit

Permalink
Extends README and translates some spanish words to english
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeleiro committed Sep 5, 2023
1 parent 1eae9e0 commit 868e3d3
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 26 deletions.
14 changes: 7 additions & 7 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#' Available tables
#'
#' A list of the available tables in the spanish 2021 Census API
#' @name tablas
#' A list of the available tables in the Spanish 2021 Census API
#' @name tables
#' @format A data frame with 7 rows and 3 columns:
#' \describe{
#' \item{id_tabla}{Table ID}
#' \item{descripcion_tabla_es, descripcion_tabla_en}{Content description of the table in spanish and english}
#' }
#' @source <https://www.ine.es/censos2021/SDC21_tablas_disponibles.xlsx>
"tablas"
"tables"
#' Available variables
#'
#' A list of the available variables in the spanish 2021 Census API
#' A list of the available variables in the Spanish 2021 Census API
#' @name variables
#' @format A data frame with 395 rows and 4 columns:
#' \describe{
Expand All @@ -23,14 +23,14 @@
"variables"
#' Available units of measurement
#'
#' A list of the available units of measurement in the spanish 2021 Census API
#' A list of the available units of measurement in the Spanish 2021 Census API
#'
#' @name metricas
#' @name metrics
#' @format A data frame with 51 rows and 4 columns:
#' \describe{
#' \item{id_tabla}{Table ID}
#' \item{id_unidad_de_medida}{unit ID}
#' \item{descripcion_unidad_de_medida_es, descripcion_unidad_de_medida_en}{Content description of the unit of measurement in spanish and english}
#' }
#' @source <https://www.ine.es/censos2021/SDC21_variables_disponibles.xlsx>
"metricas"
"metrics"
4 changes: 2 additions & 2 deletions R/get_censo.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Get data from the 2021 spanish census
#' Get data from the 2021 Spanish census
#'
#' `get_censo` retrieves data from the 2021 spanish census through the API of the National Institute of Statistics. For more info on the available tables and variables visit https://www.ine.es/dyngs/DataLab/en/manual.html?cid=1259945952385.
#' `get_censo` retrieves data from the 2021 Spanish census through the API of the National Institute of Statistics. For more info on the available tables and variables visit https://www.ine.es/dyngs/DataLab/en/manual.html?cid=1259945952385.
#'
#' @param table A string of length 1 with the table name to query data from.
#' @param variables A string with variable names of the queried table. If more than one, must be provided using c() (max. 4)
Expand Down
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,52 @@

<!-- badges: end -->

`tidycenso` is an R library for accesing the 2021 spanish census.
## Overview

It's only function `get_censo` admits 4 parameters:
`tidycenso` is an R library for accessing the 2021 Spanish census API.

## Installation

```
devtools::install_github("hmeleiro/tidycenso")
```

## Usage

`tidycenso` only has one function: `get_censo`. It admits 4 parameters:

1. table: A string of length 1 with the table name to query data from
2. variables: A string with variable names of the queried table. If more than one, must be provided using c() (max. 4)
3. metrics: A string with the units of measurement of the queried data. If more than one, must be provided concatenated using 'c()'
4. language: The language used in the request body (the only valid values are 'EN' or 'ES')

The ids and descriptions of the available tables, variables and units of measurement (metrics) are accessible through internal data objects named `tables`, `variables`, and `metrics`.

## Example

```
df <- get_censo("hog", c("ID_SUP_VIV", "ID_RESIDENCIA_N1"), "SHOGARES")
head(df)
#> SHOGARES ID_RESIDENCIA_N1 ID_SUP_VIV
#> 1 25464 Andalucía Hasta 30 m2
#> 2 2586 Aragón Hasta 30 m2
#> 3 3252 Asturias, Principado de Hasta 30 m2
#> 4 7686 Balears, Illes Hasta 30 m2
#> 5 11766 Canarias Hasta 30 m2
#> 6 1005 Cantabria Hasta 30 m2
tidycenso::tables
#> # A tibble: 7 x 3
#> id_tabla descripcion_tabla_es descripcion_tabla_en
#> <chr> <chr> <chr>
#> 1 hog Hogares Households
#> 2 nuc Parejas y otros núcleos familiares Couples and other f~
#> 3 per.estu Personas empadronadas en establecimientos ~ Persons registered ~
#> 4 per.ocu Personas residentes en viviendas familiares Persons resident in~
#> 5 per.ppal Total de Personas All persons
#> 6 viv.fam Viviendas familiares Dwellings
#> 7 viv.ppal Ocupados de 16 y más años Employed persons ag~
```
8 changes: 4 additions & 4 deletions data-raw/save-rda.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
library(dplyr)

tablas <- readxl::read_xlsx("data-raw/SDC21_tablas_disponibles.xlsx") %>%
tables <- readxl::read_xlsx("data-raw/SDC21_tablas_disponibles.xlsx") %>%
janitor::clean_names()
usethis::use_data(tablas, overwrite = T)
usethis::use_data(tables, overwrite = T)

variables <- readxl::read_xlsx("data-raw/SDC21_variables_disponibles.xlsx") %>%
janitor::clean_names()
usethis::use_data(variables, overwrite = T)

metricas <- readxl::read_xlsx("data-raw/SDC21_unidades_medida_disponibles.xlsx") %>%
metrics <- readxl::read_xlsx("data-raw/SDC21_unidades_medida_disponibles.xlsx") %>%
janitor::clean_names()
usethis::use_data(metricas, overwrite = T)
usethis::use_data(metrics, overwrite = T)
Binary file removed data/metricas.rda
Binary file not shown.
Binary file added data/metrics.rda
Binary file not shown.
Binary file removed data/tablas.rda
Binary file not shown.
Binary file added data/tables.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions man/get_censo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/metricas.Rd → man/metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/tablas.Rd → man/tables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 868e3d3

Please sign in to comment.