Package 'istacbaser'

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-09-29 02:47:50 UTC
Source: https://github.com/rOpenSpain/istacbaser

Help Index


Cached information from the ISTAC API

Description

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.

Usage

cache

Format

A data frame with 5257 rows and 11 variables:

tema

Main topic

subtemaI

Subtopic

subtemaII

third level of the topic

datos publicadosI

fourth level of the topic

datos publicadosII

fifth level of the topic

apijson

url of the table

lista_tablas

tables list

titulo

title

origen

source

encuesta

Survey title

ID

Identificator

...

Details

This data was updated on November 18, 2017


Format data of istacbase_get return from codes to labels

Description

change the data of dataframe returned by istacbase_get from the code gived by th ISTAC API to the labels gived them.

Usage

codes2labes(datos_lista, df)

Arguments

datos_lista

a list given by istacbase_get

df

a data frame with data in Code format.

Value

a data frame with the column names changed accordingly


Download data from the ISTACBASE API

Description

This function downloads the requested information using the ISTACBASE API.

Usage

istacbase(istacbase_table, islas = "all", label = TRUE,
  POSIXct = FALSE, startdate, enddate, freq, mrv, cache)

Arguments

istacbase_table

Character string with the ID of the table requested. This ID corresponds to the ID column from cache.

islas

Character vector of islands name requested. Default value is special code of all. Valid values for islands are: El Hierro, La Palma, La Gomera, Tenerife, Gran Canaria, Fuerteventura and Lanzarote.

label

if FALSE, the data frame returned has the codes used in ISTACBASE API, if TRUE, the data frame returned has the labels used in ISTACBASE API. Default value is FALSE.

POSIXct

if TRUE, additonal columns fecha and periodicidad are added. fecha converts the default date into a POSIXct. periodicidad denotes the time resolution that the date represents. Useful for freq filter, If FALSE, these fields are not added.

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.

mrv

Numeric. The number of Most Recent Values to return. A replacement of startdate and enddate, this number represents the number of observations you which to return starting from the most recent date of collection.

cache

Data frame with tables from ISTACBASE API.

Value

Data frame with all available requested data.

Note

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.

Examples

# 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)

Call the ISTACBASE API and return a formatted data frame

Description

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.

Usage

istacbase_get(indicador)

Arguments

indicador

A character string. The ID code of the requested table. Normally gived by the istacbase_search function.

Details

# To be used inside of istacbase

Value

A list with data in json format and a formatted data frame.

Examples

# 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")

Add a POSIXct dates to a ISTACBASE API return

Description

Add a POSIXct date column as well as a column with the appropreiate granularity to a ISTACBASE API return

Usage

istacbaseperiodos2POSIXct(df, date_col)

Arguments

df

data frame returned from API call

date_col

name of the current date field

Value

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.