Title: | Integrate INEGI’s (Mexican Stats Office) API with R |
---|---|
Description: | Provides functions to download and parse information from INEGI (Official Mexican statistics agency). To learn more about the API, see <https://www.inegi.org.mx/servicios/api_indicadores.html>. |
Authors: | Eduardo Flores |
Maintainer: | Eduardo Flores <[email protected]> |
License: | CC0 |
Version: | 3.0.0 |
Built: | 2025-02-18 04:25:46 UTC |
Source: | https://github.com/eflores89/inegir |
Provides functions to download and parse information from INEGI (Official Mexican statistics agency).
Package: | inegiR |
Type: | Package |
Version: | 2.0 |
Date: | 2018-03-27 |
Eduardo Flores <[email protected]>
The INEGI API can be found here: http://www.inegi.org.mx/desarrolladores/indicadores/apiindicadores.aspx
Helper function
ext_geo(x)
ext_geo(x)
x |
GeoJSON description |
Data.frame
Helper function
get_gas(token, onlyPremium = FALSE)
get_gas(token, onlyPremium = FALSE)
token |
Sakbe API token supplied by INEGI |
onlyPremium |
Only export premium price |
data.frame
Allows you to download the catalogs of frequencies, sources, notes, topics and indicator names. Called in the background in some functions.
incat_freq(token, id = NULL) incat_source(token, id = NULL) incat_notes(token, id = NULL) incat_topic(token, id = NULL) incat_indicator(token, id = NULL)
incat_freq(token, id = NULL) incat_source(token, id = NULL) incat_notes(token, id = NULL) incat_topic(token, id = NULL) incat_indicator(token, id = NULL)
token |
INEGI API token |
id |
Optional id. If NULL, will download entire catalog. |
data.frame
Eduardo Flores
# Get the corresponding frequency for frequency id #8 (monthly) ## Not run: token <- "webservice token" incat_freq(token, id = "8") ## End(Not run) # Get all of the note descriptions ## Not run: token <- "webservice token" incat_notes(token) ## End(Not run) #' # Get all of the sources descriptions ## Not run: token <- "webservice token" incat_source(token) ## End(Not run)
# Get the corresponding frequency for frequency id #8 (monthly) ## Not run: token <- "webservice token" incat_freq(token, id = "8") ## End(Not run) # Get all of the note descriptions ## Not run: token <- "webservice token" incat_notes(token) ## End(Not run) #' # Get all of the sources descriptions ## Not run: token <- "webservice token" incat_source(token) ## End(Not run)
Neumonics are shorthand names for series of economic data, akin to the Fed FRED names. This catalog downloads the neumonic with the indicator code, to easily match with an API call. This catalog is maintained by INEGI.
incat_neumonics()
incat_neumonics()
data.frame
Eduardo Flores
## Not run: catalog <- incat_neumonics() ## End(Not run)
## Not run: catalog <- incat_neumonics() ## End(Not run)
Returns Current Account revenue, expenses and total and Financial Account total, errors, reservs and adjustments for Mexico.
inegi_bop(token)
inegi_bop(token)
token |
API token supplied by INEGI |
Data.frame
Eduardo Flores
## Not run: token <- "webservice_token" balance_of_payments <- inegi_bop(token) ## End(Not run)
## Not run: token <- "webservice_token" balance_of_payments <- inegi_bop(token) ## End(Not run)
Returns data.frame with businesses registered in DENUE in the vicinity of supplied coordinates.
inegi_denue(latitud, longitud, token, meters = 250, keyword = "todos")
inegi_denue(latitud, longitud, token, meters = 250, keyword = "todos")
latitud |
Character vector with latitud (in decimals) |
longitud |
Character vector with longitud (in decimals) |
token |
API token supplied by INEGI |
meters |
Meters to search in a circle from coordinates. Defaults to 250 |
keyword |
Keyword to search in business description (in spanish). Defaults to all (todos). |
Data.frame
Eduardo Flores
# All businesses in a 1 km radius from the Macroplaza in Monterrey, Mex. ## Not run: token<-"webservice_token" latitud<- 25.669194 longitud<- -100.30990 businesses <- inegi_denue(latitud, longitud, token, meters = 1000) ## End(Not run)
# All businesses in a 1 km radius from the Macroplaza in Monterrey, Mex. ## Not run: token<-"webservice_token" latitud<- 25.669194 longitud<- -100.30990 businesses <- inegi_denue(latitud, longitud, token, meters = 1000) ## End(Not run)
Returns data.frame with businesses registered in the DENUE in spaces larger than 5 kilometers.
Calls make_grid
. Functions contributed by Arturo Cardenas https://github.com/arturocm.
inegi_denue_grid(lat1, lat2, lon1, lon2, token, meters = 5000, keyword = "todos", space_lat = 0.07, space_lon = 0.07, uniqueonly = TRUE)
inegi_denue_grid(lat1, lat2, lon1, lon2, token, meters = 5000, keyword = "todos", space_lat = 0.07, space_lon = 0.07, uniqueonly = TRUE)
lat1 |
First corner (latitud) |
lat2 |
Second corner (latitud) |
lon1 |
First corner (longitud) |
lon2 |
Second corner (longitud) |
token |
API token supplied by INEGI |
meters |
Distance in meters to search by coordinate |
keyword |
Keyword of businesses to include. Defaults to all ("todos") |
space_lat |
Space between latitud coordinates defaults to 0.07 degrees |
space_lon |
Space between longitud coordinates defaults to 0.07 degrees |
uniqueonly |
Default = TRUE, eliminates duplicate businesses |
Makes a loop for each pair of coordinates, creating a grid to extract businesses inside. Uses maximum and minimum coordinate pairs to draw frame.
Data.frame
Arturo Cardenas
## Not run: token<-"webservice_token" latitud1 <- 25.669194 latitud2 <- 25.169194 longitud1 <- -100.30990 longitud2 <- -101.20102 businesses <- inegi_denue_grid(latitud1, latitud2, longitud1, longitud2, token) ## End(Not run)
## Not run: token<-"webservice_token" latitud1 <- 25.669194 latitud2 <- 25.169194 longitud1 <- -100.30990 longitud2 <- -101.20102 businesses <- inegi_denue_grid(latitud1, latitud2, longitud1, longitud2, token) ## End(Not run)
Returns basic statistics of businesses, using DENUE, in the vecinity of coordinates.
inegi_denue_stats(latitud_vector, longitud_vector, token, meters = 250, keyword = "todos")
inegi_denue_stats(latitud_vector, longitud_vector, token, meters = 250, keyword = "todos")
latitud_vector |
number of column in data with latitud column |
longitud_vector |
number of column in data with longitud column |
token |
API token supplied by INEGI |
meters |
Distance in meters to search by coordinate |
keyword |
Keyword of businesses to include. Defaults to all ("todos") |
Some columns, like employee numbers are experimental (the employees are added considering size of company).
Data.frame
Eduardo Flores
## Not run: token<-"webservice_token" df <- as.data.frame(latitud = c(25.669194, 25.121194), longitud = c(-100.30990, -99.81923)) stats <- denue_varios_stats(data = df, col_lat = 1, col_long = 2, metros = 500) ## End(Not run)
## Not run: token<-"webservice_token" df <- as.data.frame(latitud = c(25.669194, 25.121194), longitud = c(-100.30990, -99.81923)) stats <- denue_varios_stats(data = df, col_lat = 1, col_long = 2, metros = 500) ## End(Not run)
Returns data.frame with id's and coordinates that match with the API names.
inegi_destiny(search, token)
inegi_destiny(search, token)
search |
Character vector to search for |
token |
Sakbe API token supplied by INEGI |
Data.frame
Eduardo Flores
# All id's in Monterrey, Mex. ## Not run: token <- "webservice_token" dest_ids <- inegi_destiny("monterrey", token) ## End(Not run)
# All id's in Monterrey, Mex. ## Not run: token <- "webservice_token" dest_ids <- inegi_destiny("monterrey", token) ## End(Not run)
Returns exports to main trading partners of all products. Regions are the following: United States, Canada, China, CentralAmerica, SouthAmerica
inegi_partner_exports(token)
inegi_partner_exports(token)
token |
API token supplied by INEGI |
data.frame
Eduardo Flores
## Not run: token <- "webservice_token" xbycountry <- inegi_partner_exports(token) ## End(Not run)
## Not run: token <- "webservice_token" xbycountry <- inegi_partner_exports(token) ## End(Not run)
Uses SAKBE API to return a route between two destiny id's considering the given parameters.
inegi_route(from, to, token, pref, vehicle, calc_cost = FALSE, rawJSON = FALSE)
inegi_route(from, to, token, pref, vehicle, calc_cost = FALSE, rawJSON = FALSE)
from |
Destiny id from where the route begins |
to |
Destiny id of end of route |
token |
Sakbe API token supplied by INEGI |
pref |
Preference for road: 1 = with tolls (cuota), 2 = without tolls (libre), 2 = suggested route |
vehicle |
Vehicle choice: 0 = motorcycle, 1 = auto, 2 = two axis bus, 3 = three axis bus, 4 = four axis bus, 5 = two axis truck, 6 = three axis truck, 7 = four axis truck, 8 = five axis truck, 9 = six axis truck, 10 = seven axis truck, 11 = eight axis truck, 12 = nine axis truck. |
calc_cost |
if TRUE will use the price of gasoline to calculate total cost of trip. Very experimental, defaults to FALSE. |
rawJSON |
if TRUE returns only the JSON data, not parsed |
list
To calculate the cost, it is wiser to use the more conservative estimate. Thus, this function assumes a premium type of gasoline (the most expensive) at the lower end bound of fuel-efficiency (11 kms per liter)
Eduardo Flores
See the official API here: http://www.inegi.org.mx/desarrolladores/sakbe/apisakbe.aspx
# Macroplaza in Monterrey to Mexico City airport. ## Not run: token <- "webservice_token" route <- inegi_route(from = 6940, to = 57, token, pref = 2, vehicle = 1) ## End(Not run)
# Macroplaza in Monterrey to Mexico City airport. ## Not run: token <- "webservice_token" route <- inegi_route(from = 6940, to = 57, token, pref = 2, vehicle = 1) ## End(Not run)
Returns indexes of economic sector as defined in INEGI (subsectors of IGAE). None of the series are seasonally adjusted.
inegi_sectors(token)
inegi_sectors(token)
token |
API token supplied by INEGI |
data.frame
Eduardo Flores
## Not run: token <- "webservice_token" sectors <- inegi_sectors(token) ## End(Not run)
## Not run: token <- "webservice_token" sectors <- inegi_sectors(token) ## End(Not run)
Returns a data.frame with the time series chosen from INEGI webservice. If the parameter Metadata is TRUE, a list is returned with two objects: data and metadata.
inegi_series(series_id, token, geography = "00", database = "BIE", metadata = FALSE, lastonly = FALSE, as_tt = FALSE, as_compact = FALSE)
inegi_series(series_id, token, geography = "00", database = "BIE", metadata = FALSE, lastonly = FALSE, as_tt = FALSE, as_compact = FALSE)
series_id |
an indicator ID. These are obtained via the INEGI API documentation. |
token |
API token supplied by INEGI. |
geography |
Geography code of INEGI. Defaults to 00 (National) |
database |
Is the id from BIE (Banco de Informacion Economica) or BISE (Banco de Indicadores)? Defaults to BIE. To learn more about what database your indicator is stored in, visit INEGI docs. |
metadata |
Defaults to FALSE, if TRUE, returns a list with metadata information. |
lastonly |
Do you want only the last observation? Defaults to FALSE. |
as_tt |
Do you want the output of the data.frame to be a tibble time object? Defaults to FALSE. |
as_compact |
Do you want the output always as a data.frame or time tibble? If the output contains metadata, each data point will be replicated in a column. If the output does not contain metadata there is no change. Previously, this was achieved with |
data.frame or list
Adding the entire INEGI URL as a series is deprecated since v3, due to a change of API specifications in INEGI. INEGI docs can be found at: https://www.inegi.org.mx/servicios/api_indicadores.html. Coercing biweekly indicators to monthly is also deprecated inside this function. Use tibbletime functions to coerce instead.
Eduardo Flores
## Not run: # General INPC series token <- "webservice_token" inpc_id <- "216064" INPC <- inegi_series(inpc_id, token) ## End(Not run)
## Not run: # General INPC series token <- "webservice_token" inpc_id <- "216064" INPC <- inegi_series(inpc_id, token) ## End(Not run)
Returns a data.frame with multiple time series chosen from INEGI webservice. The output will always be a data.frame (not tibble) with compacted metadata. (See inegi_series
to understand as_tt = FALSE and as_compact = TRUE).
inegi_series_multiple(series_id, token, names = NULL, geography = "00", database = "BIE")
inegi_series_multiple(series_id, token, names = NULL, geography = "00", database = "BIE")
series_id |
A vector of indicator ID's. These are obtained via the INEGI API documentation. |
token |
API token supplied by INEGI. |
names |
Optional vector of names to assign to each id. If NULL, a numerical index is assigned. |
geography |
Geography code of INEGI. Defaults to 00 (National) |
database |
Is the id from BIE (Banco de Informacion Economica) or BISE (Banco de Indicadores). Defaults to BIE. To learn more about what database your indicator is stored in, visit INEGI docs. |
data.frame
Adding the entire INEGI URL as a series is deprecated since v3, due to a change of API specifications in INEGI. INEGI docs can be found at: https://www.inegi.org.mx/servicios/api_indicadores.html. Coercing biweekly indicators to monthly is also deprecated inside this function. Use tibbletime functions to coerce instead.
Eduardo Flores
## Not run: # General INPC series token <- "webservice_token" some_series <- c("216064", "216097") result <- inegi_series_multiple(some_series, token) ## End(Not run)
## Not run: # General INPC series token <- "webservice_token" some_series <- c("216064", "216097") result <- inegi_series_multiple(some_series, token) ## End(Not run)
Returns the student price index. See http://enelmargen.org/ds/ipe/ for more information.
inegi_stind(token)
inegi_stind(token)
token |
API token supplied by INEGI |
Data.frame
Eduardo Flores
## Not run: token <- "webservice_token" studentinflation <- inegi_stind(token) ## End(Not run)
## Not run: token <- "webservice_token" studentinflation <- inegi_stind(token) ## End(Not run)
Returns the terms of trade for Mexico, defined as the price index of exports over the price index of imports.
inegi_tot(token)
inegi_tot(token)
token |
API token supplied by INEGI |
data.frame
Eduardo Flores
## Not run: token <- "webservice_token" tot <- inegi_tot(token) ## End(Not run)
## Not run: token <- "webservice_token" tot <- inegi_tot(token) ## End(Not run)
Returns exports, imports and trade balance (all products, services and countries) in a data.frame.
Wrapper for inegi_series()
and YoY()
.
inegi_tradebal(token)
inegi_tradebal(token)
token |
API token supplied by INEGI |
data.frame
Eduardo Flores
## Not run: token<-"webservice_token" external_com <- inegi_tradebal(token) ## End(Not run)
## Not run: token<-"webservice_token" external_com <- inegi_tradebal(token) ## End(Not run)
Returns common indicators, for simplicity. Will return as a list, with metadata and tibble time dataframe.
inind_commerce(token) inind_auto(token) inind_gdp(token) inind_fx(token) inind_unemp(token) inind_prices(token)
inind_commerce(token) inind_auto(token) inind_gdp(token) inind_fx(token) inind_unemp(token) inind_prices(token)
token |
API token supplied by INEGI |
inind_commerce = terciary industrial activity (commercial activity monthly). inind_auto = auto production. innind_gpd = Gross Domestic Product. inind_fx = USDMXN Exchange rate. inind_unemp = Unemployment rate. inind_prices = National price index (for inflation).
Data.frame
Eduardo Flores
## Not run: token<-"webservice_token" commerce_rate <- inind_commerce(token) ## End(Not run)
## Not run: token<-"webservice_token" commerce_rate <- inind_commerce(token) ## End(Not run)
Returns a set of coordinates that intertwine to create an area larger than 5 kilometers. Suggestion by Arturo Cardenas https://github.com/arturocm.
make_grid(lat1, lat2, lon1, lon2, space_lat = 0.07, space_lon = 0.07)
make_grid(lat1, lat2, lon1, lon2, space_lat = 0.07, space_lon = 0.07)
lat1 |
First corner (latitud). Must be numeric. |
lat2 |
Second corner (latitud). Must be numeric. |
lon1 |
First corner (longitud). Must be numeric. |
lon2 |
Second corner (longitud). Must be numeric. |
space_lat |
Space between latitud coordinates defaults to 0.07 degrees |
space_lon |
Space between longitud coordinates defaults to 0.07 degrees |
Data.frame
Arturo Cardenas
denue_grid
latitud1 <- 25.66919 latitud2 <- 25.169194 longitud1 <- -100.30990 longitud2 <- -101.20102 setofcoords <- make_grid(latitud1, latitud2, longitud1, longitud2)
latitud1 <- 25.66919 latitud2 <- 25.169194 longitud1 <- -100.30990 longitud2 <- -101.20102 setofcoords <- make_grid(latitud1, latitud2, longitud1, longitud2)