Title: | Programmatic Access to Data from the ISTAC API |
---|---|
Description: | Functions for searching and downloading data and statistics from the ISTAC API (<http://www.gobiernodecanarias.org/istac/>). |
Authors: | Cazorla-Artiles José Manuel [aut], González-Martel Christian [aut, cre] |
Maintainer: | González-Martel Christian <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-10-29 02:45:26 UTC |
Source: | https://github.com/rOpenSpain/istacbaser |
This data is a cached result of the accesibles tables using the ISTAC API.
By default functions istacbase
and istacbase_search
use this
data for the cache
parameter.
cache
cache
A data frame with 5257 rows and 11 variables:
Main topic
Subtopic
third level of the topic
fourth level of the topic
fifth level of the topic
url of the table
tables list
title
source
Survey title
Identificator
...
This data was updated on November 18, 2017
istacbase_get
return from codes to labelschange the data of dataframe returned by istacbase_get
from the code gived by th ISTAC API to the labels gived them.
codes2labes(datos_lista, df)
codes2labes(datos_lista, df)
datos_lista |
a list given by |
df |
a data frame with data in Code format. |
a data frame with the column names changed accordingly
This function downloads the requested information using the ISTACBASE API.
istacbase(istacbase_table, islas = "all", label = TRUE, POSIXct = FALSE, startdate, enddate, freq, mrv, cache)
istacbase(istacbase_table, islas = "all", label = TRUE, POSIXct = FALSE, startdate, enddate, freq, mrv, cache)
istacbase_table |
Character string with the |
islas |
Character vector of islands name requested. Default value is special code of |
label |
if |
POSIXct |
if |
startdate |
Numeric. Must be in %Y form (i.e. four digit year). |
enddate |
Numeric. Must be in %Y form (i.e. four digit year). |
freq |
Character String. For fetching yearly ("anual"), biannual ("semestral"), quaterly ("trimestral"), monthly("mensual"), bi-weekly("quincenal"), weekly("semanal") values.
Currently works along with |
mrv |
Numeric. The number of Most Recent Values to return. A replacement of |
cache |
Data frame with tables from ISTACBASE API. |
Data frame with all available requested data.
The POSIXct
parameter requries the use of lubridate
(>= 1.5.0). All dates
are rounded down to the floor. For example a value for the year 2016 would have a POSIXct
date of
2016-01-01
. If this package is not available and the POSIXct
parameter is set to TRUE
,
the parameter is ignored and a warning
is produced.
startdate
, enddate
, freq
, mrv
with POSISXct
=FALSE
are ignored when POSCIXct is set to FALSE.
and a warning
is produced.
# Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase("soc.cal.enc.res.3637") # query using startdate and enddate # Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase("soc.cal.enc.res.3637", POSIXct = TRUE, startdate = 2010, enddate = 2015) # query using \code{islas} filter # Población según sexos y edades año a año. Islas de Canarias y años. istacbase("dem.pob.exp.res.35", islas = "Fuerteventura") # if you want the most recent values istacbase("dem.pob.exp.res.35", POSIXct = TRUE, mrv = 4)
# Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase("soc.cal.enc.res.3637") # query using startdate and enddate # Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase("soc.cal.enc.res.3637", POSIXct = TRUE, startdate = 2010, enddate = 2015) # query using \code{islas} filter # Población según sexos y edades año a año. Islas de Canarias y años. istacbase("dem.pob.exp.res.35", islas = "Fuerteventura") # if you want the most recent values istacbase("dem.pob.exp.res.35", POSIXct = TRUE, mrv = 4)
This function calls the ISTACBASE API, capture the data in json format and return a list with data in json format and a formatted data frame.
istacbase_get(indicador)
istacbase_get(indicador)
indicador |
A character string. The |
# To be used inside of istacbase
A list with data in json format and a formatted data frame.
# Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase_get("soc.cal.enc.res.3637")
# Percentiles de renta disponible (año anterior al de la entrevista) por hogar en Canarias y años. istacbase_get("soc.cal.enc.res.3637")
This funcion allows finds those tables that match the search term and returns a data frame with results
istacbase_search(pattern, fields = "titulo", extra = TRUE, exact = FALSE, cache)
istacbase_search(pattern, fields = "titulo", extra = TRUE, exact = FALSE, cache)
pattern |
Character string or regular expression to be matched. |
fields |
Character vector of column name through which to search. |
extra |
if |
exact |
Search for the exact pattern. |
cache |
Data frame with metadata about API and ISTAC information. |
Data frame with metadata that match the search term.
istacbase_search(pattern = "superficie") istacbase_search(pattern = "superficie", extra = TRUE) istacbase_search(pattern = "medio ambiente", fields = "tema") istacbase_search(pattern = "medio ambiente", fields = "tema", extra = TRUE) # with regular expression operators # 'islote' OR 'roque' istacbase_search(pattern = "islote|roque")
istacbase_search(pattern = "superficie") istacbase_search(pattern = "superficie", extra = TRUE) istacbase_search(pattern = "medio ambiente", fields = "tema") istacbase_search(pattern = "medio ambiente", fields = "tema", extra = TRUE) # with regular expression operators # 'islote' OR 'roque' istacbase_search(pattern = "islote|roque")
Add a POSIXct date column as well as a column with the appropreiate granularity to a ISTACBASE API return
istacbaseperiodos2POSIXct(df, date_col)
istacbaseperiodos2POSIXct(df, date_col)
df |
data frame returned from API call |
date_col |
name of the current date field |
If the package lubridate (>= 1.5.0) is available the original data frame with two new columns,
fecha
and periodicidad
is returned. If the above package is not available,
the orignal data frame is returned unaltered with an additional warning message.