{"id":19070356,"url":"https://github.com/ropenspain/istacbaser","last_synced_at":"2026-02-26T03:07:01.740Z","repository":{"id":55440163,"uuid":"111368752","full_name":"rOpenSpain/istacbaser","owner":"rOpenSpain","description":"R-package that manages the API ISTACBASE","archived":false,"fork":false,"pushed_at":"2021-07-26T12:02:09.000Z","size":2308,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T17:19:06.599Z","etag":null,"topics":["canary-islands","istac","package","rstats","statistics"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rOpenSpain.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-20T06:06:54.000Z","updated_at":"2020-06-02T22:19:55.000Z","dependencies_parsed_at":"2022-08-15T00:20:35.217Z","dependency_job_id":null,"html_url":"https://github.com/rOpenSpain/istacbaser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2Fistacbaser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2Fistacbaser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2Fistacbaser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rOpenSpain%2Fistacbaser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rOpenSpain","download_url":"https://codeload.github.com/rOpenSpain/istacbaser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326856,"owners_count":21571637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["canary-islands","istac","package","rstats","statistics"],"created_at":"2024-11-09T01:18:17.263Z","updated_at":"2026-02-26T03:07:01.675Z","avatar_url":"https://github.com/rOpenSpain.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\n\n\n[![GitHub stars](https://img.shields.io/github/stars/rOpenSpain/istacbaser.svg?style=social\u0026label=Star\u0026maxAge=2592000)](https://GitHub.com/rOpenSpain/istacbaser/stargazers/)  [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/rOpenSpain/istacbaser/graphs/commit-activity)  [![GitHub contributors](https://img.shields.io/github/contributors/rOpenSpain/istacbaser.svg)](https://GitHub.com/rOpenSpain/istacbaser/graphs/contributors/)  [![GitHub version](https://badge.fury.io/gh/rOpenSpain%2Fistacbaser.svg)](https://github.com/rOpenSpain/istacbaser)  [![Tidyverse lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://github.com/rOpenSpain/istacbaser)    \n\n\n\n\n\n\n# Introduction\n\n\nThe [Canary Islands Statistics Institute (Instituto Canario de Estadítica, ISTAC)](http://www.gobiernodecanarias.org/istac/) is the central organ of the autonomous statistical system and official research center of the Government of the Canary Islands, created and regulated by Law 1/1991 of 28 January, Statistics of the Autonomous Community of the Canary Islands (CAC), and among others, assigns the following functions:\n\n* Providing statistical information: The ISTAC has among its objectives to provide, with technical and professional independence, statistical information of interest to the CAC, taking into account the fragmentation of the territory and its singularities and complying with the principles established in the Code of Good Practices of the European Statistics.\n\n* Coordinate public statistical activity: The ISTAC is the body responsible for promoting, managing and coordinating the public statistical activity of the CAC, assuming the exercise of the statutory competence provided for in Article 30, paragraph 23, of the Statute of Autonomy of the Canary Islands . \n\nTo help provide access to this rich source of information, ISTAC themselves, provide a well structured [API](https://es.slideshare.net/ISTAC/guia-de-uso-api-de-acceso-a-istac-base). While this API is very useful for integration into web services and other high-level applications, it becomes quickly overwhelming for researchers who have neither the time nor the expertise to develop software to interface with the API. This leaves the researcher to rely on manual bulk downloads of spreadsheets of the data they are interested in. This too is can quickly become overwhelming, as the work is manual, time consuming, and not easily reproducible.\n\n## istacbaser\n\nThe goal of the `istacbaser` R-package is to provide a bridge between these alternatives and allow researchers to focus on their research questions and not the question of accessing the data. The `istacbaser` R-package allows researchers to quickly search and download the data of their particular interest in a programmatic and reproducible fashion; this facilitates a seamless integration into their workflow and allows analysis to be quickly rerun on different areas of interest and with realtime access to the latest available data.\n\n## Installation\n\nYou can install the released version of istacbaser from [Github](https://github.com/rOpenSpain/istacbaser) with:\n\n``` r\ndevtools::install.github(\"rOpenSpain/istacbaser\")\n```\n\n### Highlighted features of the `istacbaser` R-package: \n\n- Access to all data available in the API\n- Support for searching and downloading data\n- Ability to return `POSIXct` dates for easy integration into plotting and time-series analysis techniques\n- Support for Most Recent Value queries\n- Support for `grep` style searching for data descriptions and names\n\n# Getting Started\n\nThe first step would be searching for the data you are interested in. `istacbase_search()` provides `grep` style searching of all available indicators from the ISTAC API and returns the indicator information that matches your query.\n\n\n## Finding available data with `cache`\n\nFor performance and ease of use, a cached version of useful information is provided with the `istacbaser` R-package. This data is called `cache` and provides a snapshot of available islands, indicators, and other relevant information. `cache` is by default the the source from which `istacbase_search()` and `istacbase()` uses to find matching information. The structure of `cache` is as follows\n```{r}\nlibrary(istacbaser)\n\nstr(cache, max.level = 1)\n```\n\n## Search available data with `istacbase_search()`\n\n`istacbase_search()` searches through the `cache` data frame to find indicators that match a search pattern. An example of the structure of this data frame is below\n```{r, echo=FALSE, results='asis'}\nknitr::kable(head(istacbaser::cache[4310:4311, ]))\n```\n\nBy default the search is done over the `titulo` field and returns all the columns of the matching rows. The `ID` values are inputs into `istac()`, the function for downloading the data. To return the key columns `ID` and `titulo` for the `cache` data frame, you can set `extra = TRUE`.\n```{r}\nlibrary(istacbaser)\n\nbusqueda \u003c- istacbase_search(pattern = \"parado\")\nhead(busqueda)\n\n```\n\nOther fields can be searched by simply changing the `fields` parameter. For example\n```{r}\nlibrary(istacbaser)\n\nEPA_busqueda \u003c- istacbase_search(pattern = \"Encuesta de Población Activa\", fields = \"encuesta\")\nhead(EPA_busqueda)\n\n```\n\nRegular expressions are also supported.\n```{r}\nlibrary(istacbaser)\n\n# 'pobreza' OR 'parados' OR 'trabajador'\npopatr_busqueda \u003c- istacbase_search(pattern = \"pobreza|parados|trabajador\")\n\nhead(popatr_busqueda)\n\n```\n\n## Downloading data with `istacbase()`\n\nOnce you have found the set of indicators that you would like to explore further, the next step is downloading the data with `istacbase()`. The following examples are meant to highlight the different ways in which `istacbase()` can be used and demonstrate the major optional parameters.\n\nThe default value for the `islas` parameter is a special value of `all` which as you might expect, returns data on the selected `ID` for every available country or region, if it is aviable.\n```{r}\nlibrary(istacbaser)\n\npop_data \u003c- istacbase(istacbase_table = \"dem.pob.exp.res.40\")\n\nhead(pop_data)\n```\n\nIf you are interested in only some subset of islands you can pass along the specific island to the `island` parameter. The islands that can be passed to the `islas` parameter correspond to `all`,`Canarias`,`Lanzarote`,`Fuerteventura`,`Gran Canaria`,`Tenerife`,`La Gomera`,`La Palma` or `El Hierro`.\n```{r}\nlibrary(istacbaser)\n\n# Population, total\n# country values: iso3c, iso2c, regionID, adminID, incomeID\npop_data \u003c- istacbase(islas = c(\"Lanzarote\",\"Fuerteventura\"), istacbase_table = \"dem.pob.exp.res.40\")\n\nhead(pop_data)\n```\n\n### Using `POSIXct`\n\nSetting the parameter `POSIXct = TRUE` gives you the posibility to work with dates. You can set a `startdate` and `enddate`.\n\n```{r}\nlibrary(istacbaser)\n\n# islas values: all,Canarias,Lanzarote,Fuerteventura,Gran Canaria,Tenerife,La Gomera,La Palma or El Hierro\npop_data \u003c- istacbase(islas = c(\"Lanzarote\",\"Fuerteventura\"), istacbase_table = \"dem.pob.exp.res.40\")\n\nhead(pop_data)\n```\n\n\n### Using `POSIXct = TRUE`\nThe default format for the `Periodo` or `Años` column is not conducive to sorting or plotting, especially when downloading sub annual data, such as monthly or quarterly data. To address this, if `TRUE`, the `POSIXct` parameter adds the additional columns `fecha` and `periodicidad`. `fecha` converts the default date into a `POSIXct`. `periodicidad` denotes the time resolution that the date represents. This option requires the use of the package `lubridate (\u003e= 1.5.0)`. If `POSIXct = TRUE` and `lubridate (\u003e= 1.5.0)` is not available, a `warning` is produced and the option is ignored.\n\n`startdate` and `enddate` must be in the format `YYYY`.\n \n \n\n```{r}\nlibrary(istacbaser)\n\npop_data \u003c- istacbase(istacbase_table = \"dem.pob.exp.res.40\", POSIXct = TRUE, startdate = 2010, enddate = 2016)\n\nhead(pop_data)\n```\n\nThe `POSIXct = TRUE` option makes plotting and sorting dates much easier.\n```{r, fig.height = 4, fig.width = 7.5}\nlibrary(istacbaser)\nlibrary(ggplot2)\n\npop_data \u003c- istacbase(islas = \"Canarias\", istacbase_table = \"dem.pob.exp.res.40\", POSIXct = TRUE, startdate = 2010, enddate = 2016)\n\n\nggplot(pop_data, aes(x = fecha, y = valor, colour = Nacionalidades)) +\n  geom_line(size = 1) +\n  labs(title = \"Población según sexos y nacionalidades. Islas de Canarias y años\", x = \"Fecha\", y = \"Habitantes\") +\n  theme(legend.key=element_blank(), legend.key.size=unit(1,\"point\"),\n        legend.text=element_text(size=7), axis.text.x = element_text(angle = 45, hjust = 1)) +\n  guides(colour=guide_legend(nrow=20)) +\n  facet_wrap(~ Sexos)\n```\n\n\n### Using `mrv`\nIf you do not know the latest date an indicator you are interested in is available  you can use the `mrv` instead of `startdate` and `enddate`. `mrv` stands for most recent value and takes a `integer` corresponding to the number of most recent values you wish to return\n```{r}\nlibrary(istacbaser)\n\npop_data \u003c- istacbase(istacbase_table = 'dem.pob.exp.res.40', POSIXct = TRUE, mrv = 1)\n\nhead(pop_data)\n```\n\nYou can increase this value and it will return no more than the `mrv` value. However, if `mrv` is greater than the number of available data it will return all data instead.\n\n### Using `freq`\nIf the data has several granularity, you can select son eof them with the parameter `freq`. Possible values are:\n`anual`,`semestral`,`trimestral`,`mensual`,`quincenal`,`semanal`. If the granularity selected is not aviable all granularity will be showed.\n\n```{r}\nlibrary(istacbaser)\n\nsoc_data \u003c- istacbase(istacbase_table = 'soc.sal.est.ser.1625', POSIXct = TRUE, freq = \"semestral\")\n\nhead(soc_data)\n```\n\n\n\n## `startdate`, `enddate`, `mrv`, `freq` with `POSIXct = FALSE`  \nIf you make a query with `istac()` and `POSIXct = FALSE` the `startdate`, `enddate`, `mrv`, `freq` are ignored and the function will launch a warning.\n\n```{r}\nlibrary(istacbaser)\n\nsoc_data \u003c- istacbase(istacbase_table = 'soc.sal.est.ser.1625', POSIXct = FALSE, freq = \"semestral\")\n\nhead(soc_data)\n```\n\n\n[![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://github.com/rOpenSpain/istacbaser) by [Christian González-Martel](https://github.com/chrglez) \u0026 [José Manuel Cazorla Artiles](https://github.com/jmcartiles)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropenspain%2Fistacbaser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropenspain%2Fistacbaser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropenspain%2Fistacbaser/lists"}