diff --git a/R/data.R b/R/data.R index b85b62d..1cc5dde 100644 --- a/R/data.R +++ b/R/data.R @@ -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 -"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{ @@ -23,9 +23,9 @@ "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} @@ -33,4 +33,4 @@ #' \item{descripcion_unidad_de_medida_es, descripcion_unidad_de_medida_en}{Content description of the unit of measurement in spanish and english} #' } #' @source -"metricas" +"metrics" diff --git a/R/get_censo.R b/R/get_censo.R index 5958b4f..b09e48c 100644 --- a/R/get_censo.R +++ b/R/get_censo.R @@ -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) diff --git a/README.md b/README.md index 3a10d65..addec40 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,52 @@ -`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 +#> +#> 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~ +``` diff --git a/data-raw/save-rda.R b/data-raw/save-rda.R index 34c87bb..9f27bdf 100644 --- a/data-raw/save-rda.R +++ b/data-raw/save-rda.R @@ -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) diff --git a/data/metricas.rda b/data/metricas.rda deleted file mode 100644 index cdaa3d4..0000000 Binary files a/data/metricas.rda and /dev/null differ diff --git a/data/metrics.rda b/data/metrics.rda new file mode 100644 index 0000000..783f92b Binary files /dev/null and b/data/metrics.rda differ diff --git a/data/tablas.rda b/data/tablas.rda deleted file mode 100644 index e6d3f48..0000000 Binary files a/data/tablas.rda and /dev/null differ diff --git a/data/tables.rda b/data/tables.rda new file mode 100644 index 0000000..b9127c2 Binary files /dev/null and b/data/tables.rda differ diff --git a/man/get_censo.Rd b/man/get_censo.Rd index 7699fcf..704b0d6 100644 --- a/man/get_censo.Rd +++ b/man/get_censo.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_censo.R \name{get_censo} \alias{get_censo} -\title{Get data from the 2021 spanish census} +\title{Get data from the 2021 Spanish census} \usage{ get_censo(table, variables, metrics, language = "ES") } @@ -19,7 +19,7 @@ get_censo(table, variables, metrics, language = "ES") A data.frame with the queried data } \description{ -`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. } \examples{ df <- get_censo("hog", c("ID_SUP_VIV", "ID_RESIDENCIA_N1"), "SHOGARES") diff --git a/man/metricas.Rd b/man/metrics.Rd similarity index 83% rename from man/metricas.Rd rename to man/metrics.Rd index 6cf46f6..55b1381 100644 --- a/man/metricas.Rd +++ b/man/metrics.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} -\name{metricas} -\alias{metricas} +\name{metrics} +\alias{metrics} \title{Available units of measurement} \format{ A data frame with 51 rows and 4 columns: @@ -16,9 +16,9 @@ A data frame with 51 rows and 4 columns: } \usage{ -metricas +metrics } \description{ -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 } \keyword{datasets} diff --git a/man/tablas.Rd b/man/tables.Rd similarity index 81% rename from man/tablas.Rd rename to man/tables.Rd index 633c499..5c8ad7d 100644 --- a/man/tablas.Rd +++ b/man/tables.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} -\name{tablas} -\alias{tablas} +\name{tables} +\alias{tables} \title{Available tables} \format{ A data frame with 7 rows and 3 columns: @@ -15,9 +15,9 @@ A data frame with 7 rows and 3 columns: } \usage{ -tablas +tables } \description{ -A list of the available tables in the spanish 2021 Census API +A list of the available tables in the Spanish 2021 Census API } \keyword{datasets} diff --git a/man/variables.Rd b/man/variables.Rd index 8396be6..b3a2231 100644 --- a/man/variables.Rd +++ b/man/variables.Rd @@ -19,6 +19,6 @@ A data frame with 395 rows and 4 columns: variables } \description{ -A list of the available variables in the spanish 2021 Census API +A list of the available variables in the Spanish 2021 Census API } \keyword{datasets}