From 37402c5faa32cb64989c23a4c9ca4e352428b4e2 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:00:31 +0100 Subject: [PATCH 1/7] frontur - adding mdat1 and mdat2 files --- inst/metadata/frontur_2016_mdat1.txt | 12 +++++ inst/metadata/frontur_2016_mdat2.txt | 72 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 inst/metadata/frontur_2016_mdat1.txt create mode 100644 inst/metadata/frontur_2016_mdat2.txt diff --git a/inst/metadata/frontur_2016_mdat1.txt b/inst/metadata/frontur_2016_mdat1.txt new file mode 100644 index 0000000..184953a --- /dev/null +++ b/inst/metadata/frontur_2016_mdat1.txt @@ -0,0 +1,12 @@ +var start end width descr +A0 1 1 1 Encuesta de procedencia +A0_1 2 15 14 Identificador cuestionario +A0_7 16 16 1 Tipo de viajero +A1 17 17 1 Vía de Entrada de los turistas +Residencia 18 19 2 Pais de residencia habitual +CCAA 20 21 2 Comunidad Autónoma de destino principal del viaje +A14 22 22 1 Alojamiento principal +A15 23 23 1 Motivo del viaje +A16 24 24 1 Utilización de paquete turístico +A13_1 25 25 1 Duración del viaje +Factor 26 37 12 Factor de elevación de la encuesta diff --git a/inst/metadata/frontur_2016_mdat2.txt b/inst/metadata/frontur_2016_mdat2.txt new file mode 100644 index 0000000..a561b30 --- /dev/null +++ b/inst/metadata/frontur_2016_mdat2.txt @@ -0,0 +1,72 @@ +"var" "tipo" "nulo" "llave" "valor" +"A0" "D" NA "1" "FRONTUR" +"A0" "D" NA "2" "EGATUR" +"A0_1" "D" NA NA "" +"A0_7" "D" NA "2" "Turista no residente" +"A0_7" "D" NA "3" "Excursionista No Residente" +"A1" "D" NA "1" "Carretera" +"A1" "D" NA "2" "Aeropuerto" +"A1" "D" NA "3" "Ferry/Barco" +"A1" "D" NA "4" "Tren" +"Residencia" "D" NA "1" "Alemania" +"Residencia" "D" NA "2" "Bélgica" +"Residencia" "D" NA "3" "España" +"Residencia" "D" NA "4" "Francia" +"Residencia" "D" NA "5" "Irlanda" +"Residencia" "D" NA "6" "Italia" +"Residencia" "D" NA "7" "Países Bajos" +"Residencia" "D" NA "8" "Portugal" +"Residencia" "D" NA "9" "Reino Unido" +"Residencia" "D" NA "10" "Países Nordicos" +"Residencia" "D" NA "11" "Rusia" +"Residencia" "D" NA "12" "Suiza" +"Residencia" "D" NA "13" "Resto de Europa" +"Residencia" "D" NA "14" "Estados Unidos de América" +"Residencia" "D" NA "15" "América (sin EEUU)" +"Residencia" "D" NA "16" "Resto del mundo" +"CCAA" "D" NA "01" "Andalucía" +"CCAA" "D" NA "02" "Aragón" +"CCAA" "D" NA "03" "Principado de Asturias" +"CCAA" "D" NA "04" "Baleares" +"CCAA" "D" NA "05" "Canarias" +"CCAA" "D" NA "06" "Cantabria" +"CCAA" "D" NA "07" "Castilla y León" +"CCAA" "D" NA "08" "Castilla La Mancha" +"CCAA" "D" NA "09" "Cataluña" +"CCAA" "D" NA "10" "Com.Valenciana" +"CCAA" "D" NA "11" "Extremadura" +"CCAA" "D" NA "12" "Galicia" +"CCAA" "D" NA "13" "Com.Madrid" +"CCAA" "D" NA "14" "Región de Murcia" +"CCAA" "D" NA "15" "C.F.Navarra" +"CCAA" "D" NA "16" "País Vasco" +"CCAA" "D" NA "17" "La Rioja" +"CCAA" "D" NA "18" "Ceuta" +"CCAA" "D" NA "19" "Melilla" +"CCAA" "D" NA "98" "Transito" +"A14" "D" NA "1" "Hoteles y Similares" +"A14" "D" NA "2" "Alojamiento alquiler" +"A14" "D" NA "3" "Camping" +"A14" "D" NA "4" "Casa rural" +"A14" "D" NA "5" "Crucero" +"A14" "D" NA "6" "Otro alojamiento mercado" +"A14" "D" NA "7" "Vivienda en propiedad" +"A14" "D" NA "8" "Vivienda familiares/amigos" +"A14" "D" NA "9" "Otro alojamiento no mercado" +"A14" "D" NA "0" "No procede" +"A15" "D" NA "0" "No procede" +"A15" "D" NA "1" "Ocio/vacaciones" +"A15" "D" NA "2" "Negocios" +"A15" "D" NA "3" "Estudios" +"A15" "D" NA "4" "Personal (salud, familia)" +"A15" "D" NA "5" "Otros motivos" +"A16" "D" NA "1" "Sí" +"A16" "D" NA "6" "No" +"A16" "D" NA "0" "No procede" +"A13_1" "D" NA "1" "Ninguna noche" +"A13_1" "D" NA "2" "1 noche" +"A13_1" "D" NA "3" "De 2 a 3 noches" +"A13_1" "D" NA "4" "De 4 a 7 noches" +"A13_1" "D" NA "5" "De 8 a 15 noches" +"A13_1" "D" NA "6" "Más de 15 noches" +"Factor" "N" NA NA "" From 4cbfe8fe16722632fd2bb9adec63c722abf19847 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:01:01 +0100 Subject: [PATCH 2/7] frontur - adding sample frontur file --- inst/extdata/sample_frontur_2016.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 inst/extdata/sample_frontur_2016.txt diff --git a/inst/extdata/sample_frontur_2016.txt b/inst/extdata/sample_frontur_2016.txt new file mode 100644 index 0000000..0eceace --- /dev/null +++ b/inst/extdata/sample_frontur_2016.txt @@ -0,0 +1,17 @@ +A0;A0_1;A0_7;A1;Residencia;CCAA;A14;A15;A16;A13_1;Factor +1;20181101031507;2;2;13;09;2;1;6;6;99.623143409 +1;20181100031507;2;2;13;09;2;1;6;6;99.623143409 +1;20181100017107;2;2;13;04;1;2;6;4;25.519607901 +1;20181100018507;3;2;13;98;0;1;6;1;385.55899129 +1;20181100012913;2;2;13;09;8;1;6;6;163.65133432 +1;20181100006388;3;2;13;98;0;1;6;1;104.04387009 +1;20181100013667;2;2;13;13;1;1;6;5;82.442475534 +1;20181100006386;2;2;13;09;1;2;6;6;75.085969225 +1;20181000010082;3;2;13;09;0;1;6;1;113.5132676 +1;20181100003142;2;2;13;09;1;1;6;3;91.108450254 +2;20181100002871;2;2;13;04;1;1;1;5;25.616372281 +2;20181102002874;2;2;13;04;2;1;6;4;53.69196178 +1;20181101004187;2;2;13;09;1;1;6;4;167.02122322 +2;20181101002876;2;2;13;04;1;1;6;3;25.637361136 +1;20181100000882;2;2;13;09;6;1;6;4;284.5585924 +2;20181105003208;2;2;13;09;1;1;6;4;264.70615886 From 0a8b6595412da161af238a30b7f7fd0c90c729c7 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:01:51 +0100 Subject: [PATCH 3/7] frontur - updating NAMESPACE --- NAMESPACE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 248f304..73f7960 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ -importFrom("readr", "read_fwf", "fwf_widths") +importFrom("readr", "read_fwf", "fwf_widths", "read_csv2") importFrom("utils", "read.table") export(epa2005, test.metadata, defun2011, ees2010, censo2010, epf.2011.gastos, epf.2011.hogares, - epf.2011.miembros, padron2016) + epf.2011.miembros, padron2016, frontur2016) From 62cc0db3d27933bbc23b4f68aff0be21b80c03e0 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:03:44 +0100 Subject: [PATCH 4/7] frontur - adding main script frontur --- R/frontur2016.R | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 R/frontur2016.R diff --git a/R/frontur2016.R b/R/frontur2016.R new file mode 100644 index 0000000..cf47f3f --- /dev/null +++ b/R/frontur2016.R @@ -0,0 +1,45 @@ +#' Download data from the "Frontur" +#' +#' This function downloads data from the Spanish "frontur" using the information provided by the Spanish Statistical Office (INE). +#' +#' @param file Character string with the name of the microdata file provided by the INE on the +#' \href{http://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736177012&menu=resultados&secc=1254736195462&idp=1254734710990}{Padrón} section. It allows either a path to a file, +#' or literal data (single string or raw vector). It also allows compressed files in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} format. +#' +#' @return \code{\link[tibble]{tibble}} with all avaliable requested data where each row corresponds to an anonymised citizen. +#' @details This function reads microdata from the members approach of the "Padrón" in Spain. It was originally built using the metadata for 2016 file but it may be used for later years. Previous files have a different, non compatible, format. +#' +#' @author David Carrasco. +#' @note The \code{file} parameter allows any flat file with fixed width. +#' @references http://www.ine.es/prodyser/microdatos.htm +#' @examples +#' \dontrun{ +#' raw <- frontur2016("sample_frontur_2016.txt") +#' summary(raw) +#' } +#' @seealso \code{\link[read_fwf]{readr}} to read fixed width files. + + +################################################################### +# David-Carrasco +# 20190327 +# Reads the "frontur" microdata in its 2016 (and probably others) version +################################################################### + +frontur2016 <- function(file){ + + mdat.1 <- read.table('inst/metadata/frontur_2016_mdat1.txt', + header = T, sep = "\t", + fileEncoding = "UTF-8", + stringsAsFactors = FALSE) + + suppressMessages( + dat <- read_csv2(file, col_names = mdat.1$var, skip=1, col_types = "ccccccccccc") + ) + + read.fwf.microdata(dat, + system.file("metadata", "frontur_2016_mdat1.txt", package = "MicroDatosEs"), + system.file("metadata", "frontur_2016_mdat2.txt", package = "MicroDatosEs"), + fileEncoding = "UTF-8") +} + From 7813bd484164657fe4686f89f4174e2c7e9c51f3 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:04:20 +0100 Subject: [PATCH 5/7] frontur - doc --- man/frontur2016.Rd | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 man/frontur2016.Rd diff --git a/man/frontur2016.Rd b/man/frontur2016.Rd new file mode 100644 index 0000000..a4555f1 --- /dev/null +++ b/man/frontur2016.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/frontur2016.R +\name{frontur2016} +\alias{frontur2016} +\title{Download data for "Estadística de movimientos turísticos en frontera - FRONTUR" from INE} +\usage{ +frontur2016(file) +} +\arguments{ +\item{file}{Character string with the name of the microdata file provided by the INE on the +\href{http://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736176996&menu=resultados&secc=1254736195382&idp=1254735576863}{FRONTUR} section. It allows either a path to a file +or literal data (single string or raw vector). It also allows compressed files in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} format.} +} +\value{ +\code{\link[tibble]{tibble}} with all avaliable requested data where each row corresponds to an anonymised citizen. +} +\description{ +This function downloads FRONTUR statistcs from the Spanish Statistical Office (INE). +} +\details{ +This function reads deaths microdata in Spain. + +It was originally built using the metadata for the 2016 file and may work with microdata files for other yearly submissions. Previous files have a different, non compatible, format. +} +\note{ +The \code{file} parameter allows any flat file with fixed width. +} +\examples{ +\dontrun{ +raw <- frontur2016("datos_1_19.zip") # It will be automatically uncompressed. +summary(raw) +} +} +\references{ +http://www.ine.es/prodyser/microdatos.htm +} +\seealso{ +\code{\link[read_fwf]{readr}} to read fixed width files. +} +\author{ +Carlos J. Gil Bellosta, David Carrasco +} From aba765991963c2ae1da95555ca7204d9c8db6096 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:05:33 +0100 Subject: [PATCH 6/7] frontur - update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 69994be..5bd41d5 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ It is intended mostly for microdata which is generated periodically with the sam * **Mortality** (Annual deaths in Spain): unfortunately, public microdata does not include the cause of death. * **EPF** (Encuesta de presupuestos familiares) * **Padrón** +* **Frontur** ## Use cases and examples From bc5eec7ae6e37e3ace63725e7a3378541337dfb5 Mon Sep 17 00:00:00 2001 From: David-Carrasco Date: Wed, 27 Mar 2019 14:23:12 +0100 Subject: [PATCH 7/7] frontur - fix mdat1 endpoint file and documentation --- R/frontur2016.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/frontur2016.R b/R/frontur2016.R index cf47f3f..057254b 100644 --- a/R/frontur2016.R +++ b/R/frontur2016.R @@ -1,9 +1,9 @@ #' Download data from the "Frontur" #' -#' This function downloads data from the Spanish "frontur" using the information provided by the Spanish Statistical Office (INE). +#' This function downloads data from the Spanish "FRONTUR" using the information provided by the Spanish Statistical Office (INE). #' #' @param file Character string with the name of the microdata file provided by the INE on the -#' \href{http://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736177012&menu=resultados&secc=1254736195462&idp=1254734710990}{Padrón} section. It allows either a path to a file, +#' \href{http://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736176996&menu=resultados&secc=1254736195382&idp=1254735576863}{FRONTUR} section. It allows either a path to a file, #' or literal data (single string or raw vector). It also allows compressed files in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} format. #' #' @return \code{\link[tibble]{tibble}} with all avaliable requested data where each row corresponds to an anonymised citizen. @@ -28,7 +28,7 @@ frontur2016 <- function(file){ - mdat.1 <- read.table('inst/metadata/frontur_2016_mdat1.txt', + mdat.1 <- read.table(system.file("metadata", "frontur_2016_mdat1.txt", package = "MicroDatosEs"), header = T, sep = "\t", fileEncoding = "UTF-8", stringsAsFactors = FALSE)