From 868e3d33d10fdaeba8a1d5b19927e2a42b82e797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Meleiro?= Date: Tue, 5 Sep 2023 09:21:15 +0200 Subject: [PATCH] Extends README and translates some spanish words to english --- R/data.R | 14 +++++----- R/get_censo.R | 4 +-- README.md | 45 ++++++++++++++++++++++++++++++-- data-raw/save-rda.R | 8 +++--- data/metricas.rda | Bin 1340 -> 0 bytes data/metrics.rda | Bin 0 -> 1340 bytes data/tablas.rda | Bin 502 -> 0 bytes data/tables.rda | Bin 0 -> 498 bytes man/get_censo.Rd | 4 +-- man/{metricas.Rd => metrics.Rd} | 8 +++--- man/{tablas.Rd => tables.Rd} | 8 +++--- man/variables.Rd | 2 +- 12 files changed, 67 insertions(+), 26 deletions(-) delete mode 100644 data/metricas.rda create mode 100644 data/metrics.rda delete mode 100644 data/tablas.rda create mode 100644 data/tables.rda rename man/{metricas.Rd => metrics.Rd} (83%) rename man/{tablas.Rd => tables.Rd} (81%) 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 cdaa3d42bd19feaec19e354f7b0ba7062ed3ec56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1340 zcmcJ@{X5eM003~&T<+SF+w$_2i!zK*<}HmBX4u9VtC^Bn3(+dCmDiqAZW-FvEaYM) zOp><=BX!oi+$JxXq!`IdL|&3r-1FT3aGxJPuB32B>*IkY{((lpAv6`xt<=%2t!HRnWU*~V;k!I9|`i( zJf_(PY?uCiEgumvbDfO?v(4rxZvIk;eF>UReASp4dP$hcXHHk_-mv=-Y;oKMo_s%} zIw`+A+2ux+JM-u+AJLIatReu<$k6ial^%WSfOPim`%;qefZP%p_D7HWwO~&JYtU|` zE!8A3hZos{20~Xp^q-!tHb@&_qhx@GzNMn|P%B_S`*dp#{>=MfoKC{|ucT4|sdOr# zCHyy4Po9P!esn0!XMunUAh-wMImTMX5IPFIUVdd(W0a4Mm7B)LPd^6i)o<=(r<|^00wI8AaQga?;9*V)HFNC%11^VN-(E z?Tb;PPCZ##&QEf28EEX8kw1}FbKI`a9WDzNG=rVn<`YRNB}G$?DNV?-J}yz>?>WEW zE4wNZCzah>^&L-PS3aF_`ltXG;8)G{D)*wh}_A$;RolJUYYJ% z79kd)Qw@YvI)- zrq>A5&28xy%;4vV-9Z_@z&>0ov;AOhxt9VpIK?^x)${A9&m_407-Z(XWy4trxXo>2K@>#4Qn>Gm-@nLCU4lD6Or;Efw`61DC6r4v*b7n7gKy72(~O41cRqwd3)X2X&2>@!#)CyGsb$9=X!vB&v{#zSHXKvo^Y z^4fC+{}6Sw>+Z~hFC)+*QhXg#3M-Jp!QB%W$cook* zvN|g?-W(M~I*O61vGzs%?-S0lAKN%|cE8vdpaj;@CUasExpX639*P4i-0`i??+~Ul z+HjU+YK{sj?8JKiN#aGXiTP{|SdH5Q#wD^)0@{@USi&wMEXBldV-D_ZC0Tp?43*+< zmM(N%+011R2ZWG!Ps&aJUD`q0iN$D?GK%FJ*%c+*ckf)Z5p)>-3ay9A4hCF{iA_JB zx;K)w!jL75NTX_KOe^AIhiJa=F4cON#?=GqEF?5xVbaRQwJuYI<|lmxBfCzNIzL#w PY4!frrD8)5QTyn>(>{SQ diff --git a/data/metrics.rda b/data/metrics.rda new file mode 100644 index 0000000000000000000000000000000000000000..783f92b85eebed7a58d66d75272314ec5d4a9436 GIT binary patch literal 1340 zcmcJ@`8(4M008incwVG86Bf0Xw&lK~97D9NuVr3$MzlBKF|9F z9(-kBwLW?N&HChbcaXtulTHBD#cvIu7oXl%WX5;go zM-NSp^EW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GGx(&!7((zCIJi)ffxjeCaL8;OrDcRsh|J=0BQQ8O&Vx4Kr6XsiFH)M34+9*LJ9^2Yz;}zO-hWGMsdeoG}929t@|@t=!0DeFae>cJobcw`)w({mV)y| z{7$rBc6~ubk;J9mu(W8~G$#C-H%L2!F+@5l*H?_xSK-6wZMM^8uX|0-CYUEl zgCN!;IfSlN28bwKO-3hqvA{=yBa|21bjyJ5ZBiVBO+M;i5}FvtDDu ztr!g{GPs(hXhgRHpvfwUNT?e`a^8gvyyb5E6(t0eLJHbOCMpG_TWR;-MOj@2uJp~{r#YiMv=4%oSyzN(} s+h&XE6;A${y$5Qvd(} diff --git a/data/tables.rda b/data/tables.rda new file mode 100644 index 0000000000000000000000000000000000000000..b9127c23b1a7acd443393e9fd5383b4eb0b5aa49 GIT binary patch literal 498 zcmVayLY|`ufiwny00U1^kkdh;0amrEC51}}CJQQ#NJJHSbZa1!UfN-i zp#;MMrUmNjx}`RIQLaAKQAH67-A^+%EC?|nCIB=w2dL1HTy3RW>1ZvqT*~T37i;PY zERDpg!h(>&vS=oCFmlLC^0^R$fKgOI_<3K_^ZE2n*Bo)d6mvH{U_9_e!v;Z#1p^4q z>O%w)Il&2xN)t%@&O=j62<)cGcwD&z zu_J&$7sF*qZNZ-PwXP%N$DF)FU7U45)b$@;ef?`S`1%80dnGS$xE~yvAuFGon*!J6KO>9=2 z6hpBaK}uMjLm{TR8GyNW##4cX;%go_Nz)ldPWSA^1k8aV1WRl$L}sAYZlsRcdKI4O o!mCc_0_1`cDW-;XtelmJ4*AS!TUTuVNMrvOaz!{$kg)NNPZT5AGXMYp literal 0 HcmV?d00001 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}