Title: | Download and Tidy IPC and CH Data |
---|---|
Description: | Utilities to access Integrated Food Security Phase Classification (IPC) and Cadre Harmonisé (CH) food security data. Wrapper functions are available for all of the 'IPC-CH' Public API (<https://docs.api.ipcinfo.org>) simplified and advanced endpoints to easily download the data in a clean and tidy format. |
Authors: | Seth Caldwell [aut, cre, cph] |
Maintainer: | Seth Caldwell <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.1 |
Built: | 2024-11-11 05:00:31 UTC |
Source: | https://github.com/ocha-dap/ripc |
Back-end function used to drive the API calls of the other ipc_get_...()
family of functions.
ipc_get(resource, return_format, pass_format, api_key = NULL, ...)
ipc_get(resource, return_format, pass_format, api_key = NULL, ...)
resource |
One of the resources exposed in the IPC API, such
|
return_format |
The format that should be returned by the API. Allows
|
pass_format |
Pass format explicitly in the API call. |
api_key |
IPC API key. If |
... |
Named parameters passed to the API call URL in the form of
|
Data frame from the API
Accesses the areas resources on the IPC API. Contains detailed analysis
information. If country
, year
and/or type
parameters are passed,
accesses the analyses simplified API endpoint and pulls in all analyses or
filtered to those parameters. To get the details for a specific analysis
available on the analyses/{id}/{period} advanced API endpoint,
pass in id
. You cannot pass in both sets of parameters.
ipc_get_analyses( country = NULL, year = NULL, type = NULL, id = NULL, api_key = NULL, tidy_df = TRUE )
ipc_get_analyses( country = NULL, year = NULL, type = NULL, id = NULL, api_key = NULL, tidy_df = TRUE )
country |
ISO2 country code. |
year |
Single numeric year to filter analysis, calculated from the
maximum year of current period dates. If |
type |
Single string value of 'A' or 'C', corresponding to food security
conditions, either acute or chronic. If |
id |
Analysis ID. |
api_key |
IPC API key. If |
tidy_df |
If |
Analyses data is metadata related to specific analyses conducted by the IPC, including title of the analysis, link to its release page on the IPC website, and creation/modification dates.
Data frame of analysis metadata. Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, the following changes are made to the initial
output to ensure each row represents a single analysis:
The data is arranged by country
, year
, and created
.
id
column is renamed to be analysis_id
.
# get all analyses details from the simplified API ipc_get_analyses() # get analysis details for a specific analysis ID ipc_get_analyses(id = 12856213)
# get all analyses details from the simplified API ipc_get_analyses() # get analysis details for a specific analysis ID ipc_get_analyses(id = 12856213)
Accesses the areas resources on the IPC-CH API. Contains detailed area and
population data. If country
, year
and/or type
parameters are passed,
accesses the areas simplified API endpoint and pulls in all areas filtered to
those parameters. To get all areas for a specific analysis
and period, available on the areas/{id}/{period} advanced API endpoint,
pass in id
and period
. You cannot pass in both sets of parameters.
ipc_get_areas( country = NULL, year = NULL, type = NULL, id = NULL, period = NULL, return_format = c("csv", "geojson"), api_key = NULL, tidy_df = TRUE )
ipc_get_areas( country = NULL, year = NULL, type = NULL, id = NULL, period = NULL, return_format = c("csv", "geojson"), api_key = NULL, tidy_df = TRUE )
country |
ISO2 country code. |
year |
Single numeric year to filter analysis, calculated from the
maximum year of current period dates. If |
type |
Single string value of 'A' or 'C', corresponding to food security
conditions, either acute or chronic. If |
id |
Analysis ID. |
period |
Period code, either 'C', 'P', or 'A' for current, projection, and second projection. |
return_format |
The format that should be returned by the API. Allows
|
api_key |
IPC API key. If |
tidy_df |
If |
Areas data is the typical unit of analysis in IPC-CH outputs. These are
typically administrative units (or clusters of them together). For each area,
estimates of the population in each phase is provided and a general phase
classification is assigned. Use ipc_get_population()
to get
detailed population data and classifications for all analysis periods.
See the IPC website and API documentation for more information.
Data frame of IPC and CH analysis at the areas level. Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, the following changes are made to the initial
output to ensure each row represents a single area analysis, and all estimates
and values are stored as columns:
analysis_period_start
and analysis_period_end
created as Date
columns
from the from
and to
columns respectively, allocating the day of the
start and end periods to be the 15th of the month.
title
column is renamed to be area_name
, anl_id
to analysis_id
,
and id
and aar_id
are changed to area_id
.
Duplicated rows are removed from the data frame if the return value is CSV, because the duplicates are there due to polygon geometries.
# get all areas from the simplified API ipc_get_areas() # get areas for specific analysis ID and period from advanced API ipc_get_areas(id = 12856213, period = "P") # request GeoJSON return ipc_get_areas(id = 12856213, period = "P", return_format = "geojson")
# get all areas from the simplified API ipc_get_areas() # get areas for specific analysis ID and period from advanced API ipc_get_areas(id = 12856213, period = "P") # request GeoJSON return ipc_get_areas(id = 12856213, period = "P", return_format = "geojson")
Accesses the country resources on the IPC API. Contains detailed
country-level data. If country
, year
and/or type
parameters are passed,
accesses the country simplified API endpoint and pulls in all country data
filtered to those parameters.
ipc_get_country( country = NULL, year = NULL, type = NULL, api_key = NULL, tidy_df = TRUE )
ipc_get_country( country = NULL, year = NULL, type = NULL, api_key = NULL, tidy_df = TRUE )
country |
ISO2 country code. |
year |
Single numeric year to filter analysis, calculated from the
maximum year of current period dates. If |
type |
Single string value of 'A' or 'C', corresponding to food security
conditions, either acute or chronic. If |
api_key |
IPC API key. If |
tidy_df |
If |
Country data is the highest level of aggregation for IPC analysis. Data is
the population estimates and other details aggregated from area and point
analyses within the country for that specific analysis. No phase
classifications are made at the country level. Data is currently output only
for current periods through the country endpoint. Use
ipc_get_population()
to get detailed population data for all analysis
periods.
See the IPC website and API documentation for more information.
Data frame of IPC and CH analysis at the country level. Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, the following changes are made to the initial
output to ensure each row represents a single country analysis, and all estimates
and values are stored as columns:
analysis_period_start
and analysis_period_end
created as Date
columns
from the from
and to
columns respectively, allocating the day of the
start and end periods to be the 15th of the month.
id
column is renamed to be analysis_id
.
# get all areas from the simplified API ipc_get_country() # get country data just for Somalia ipc_get_country(country = "SO")
# get all areas from the simplified API ipc_get_country() # get country data just for Somalia ipc_get_country(country = "SO")
Accesses the icons resources on the IPC API. Contains links from analysis and
area IDs to the icon resource the IPC uses in maps and publications. This
is likely not useful for the general user. If year
and/or type
parameters are passed, accesses the icons simplified API endpoint, pulls in
data filtered to those parameters. To get all icons for a specific analysis
and period, available on the types/{id}/{period} advanced API endpoint,
pass in id
and period
. You cannot pass in both sets of parameters.
ipc_get_icons( year = NULL, type = NULL, id = NULL, period = NULL, api_key = NULL, tidy_df = TRUE )
ipc_get_icons( year = NULL, type = NULL, id = NULL, period = NULL, api_key = NULL, tidy_df = TRUE )
year |
Single numeric year to filter analysis, calculated from the
maximum year of current period dates. If |
type |
Single string value of 'A' or 'C', corresponding to food security
conditions, either acute or chronic. If |
id |
Analysis ID. |
period |
Period code, either 'C', 'P', or 'A' for current, projection, and second projection. |
api_key |
IPC API key. If |
tidy_df |
If |
Icons data is used internally by the IPC to link up analyses for areas and a relevant icon for display on maps and in publications. The icons are stored in an Amazon S3 bucket that is not publicly accessible and therefore not useful for general users. Provided here for convenience.
See the IPC website and API documentation for more information.
Data from of icons for analysis publications. Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, aar_id
is renamed to area_id
and area
to
area_name
.
# get all icons from the simplified API ipc_get_icons() # get icons for specific analysis ID and period from advanced API ipc_get_icons(id = 12135625, period = "C")
# get all icons from the simplified API ipc_get_icons() # get icons for specific analysis ID and period from advanced API ipc_get_icons(id = 12135625, period = "C")
Accesses the points resources on the IPC API. Contains detailed area and
population data. If year
and/or type
parameters are passed, accesses
the types simplified API endpoint and pulls in all types data or filtered to
either year
or type
. To get all types for a specific analysis
and period, available on the types/{id}/{period} advanced API endpoint,
pass in id
and period
. You cannot pass in both sets of parameters.
ipc_get_points( year = NULL, type = NULL, id = NULL, period = NULL, api_key = NULL, tidy_df = TRUE )
ipc_get_points( year = NULL, type = NULL, id = NULL, period = NULL, api_key = NULL, tidy_df = TRUE )
year |
Single numeric year to filter analysis, calculated from the
maximum year of current period dates. If |
type |
Single string value of 'A' or 'C', corresponding to food security
conditions, either acute or chronic. If |
id |
Analysis ID. |
period |
Period code, either 'C', 'P', or 'A' for current, projection, and second projection. |
api_key |
IPC API key. If |
tidy_df |
If |
Points data is IPC data generated from analysis on geographic
entities that are smaller than the standard areas. These are typically
urban areas or displacement sites where food insecurity conditions might
differ significantly from the wider context and justify specific analysis.
Population estimates as well as an overall phase classification are provided
for each point. Data is currently output only for current
periods through the points endpoint. Use ipc_get_population()
to get
detailed population data and classifications for all analysis periods. Points
data is contained within the areas
dataset returned from
ipc_get_population()
.
See the IPC website and API documentation for more information.
Data frame of IPC and CH analysis at the point level. Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, the following changes are made to the initial
output to ensure each row represents a single point analysis, and all estimates
and values are stored as columns:
All columns containing phase
or population
are converted to numeric.
aar_id
is renamed to area_id
and anl_id
to analysis_id
.
# get all areas from the simplified API ipc_get_points() # get areas for specific analysis ID and period from advanced API ipc_get_points(id = 18978466, period = "P")
# get all areas from the simplified API ipc_get_points() # get areas for specific analysis ID and period from advanced API ipc_get_points(id = 18978466, period = "P")
Accesses the population resources on the IPC API. Contains detailed
population data. If country
and/or start
and end
parameters are passed,
accesses the population advanced API endpoint and pulls in all data.
filtered by those parameters. To get the population data for a specific
analysis, available on the types/{id} advanced API endpoint,
pass in id
. You cannot pass in both sets of parameters.
ipc_get_population( country = NULL, start = NULL, end = NULL, id = NULL, api_key = NULL, tidy_df = TRUE )
ipc_get_population( country = NULL, start = NULL, end = NULL, id = NULL, api_key = NULL, tidy_df = TRUE )
country |
ISO2 country code. |
start |
Start year. |
end |
End year. |
id |
Analysis ID. |
api_key |
IPC API key. If |
tidy_df |
If |
Unlike the other ipc_get_..()
family of functions, this returns a list of
datasets, corresponding to country
, areas
, and groups
data. The benefit of
ipc_get_population()
is that the
returned data for each level of analysis contains all periods of analysis.
Groups data, where available, are geographies within a country that comprise multiple areas and/or points. Areas and points data is the lowest level of IPC analysis where population estimates for each phase are provided and a general area-level classification is made. There is no phase classification at the group level, but populations in each phase are provided. The same applies to country-level data.
These datasets are available elsewhere through:
Country data: ipc_get_country()
Areas data: ipc_get_areas()
Groups data: Not available through other functions
See the respective function documentation for more details on what each dataset comprises or the IPC website and API documentation for more detailed and comprehensive information on the data and analysis.
A list of 3 data frames:
Country data frame.
Areas data frame.
Groups data frame.
Refer to the IPC-CH Public API documentation for details on the returned values, with variables described in full in the extended documentation.
When tidy_df
is TRUE
, the data returned from the population end point is
transformed into a list of 3 data frames to ensure that each row represents a
single analysis, and all estimates and values are stored as columns, while
data at different levels of aggregation are in completely separate data
frames. The steps are:
analysis_period_start
and analysis_period_end
created as Date
columns
from the period_dates
column respectively, allocating the day of the
start and end periods to be the 15th of the month.
analysis_date
converted to a date column, using the 15th day of the month.
phases
is unnested from a list column to bring the phase data into
the main data frame.
The population estimates are pivoted to a wider format with names phase#_num
and phase#_pct
.
id
column renamed to analysis_id
.
Data frames are split out so multiple aggregations not present in a single single data frame.
# get all populations from the simplified API ipc_get_population() # get populations for specific analysis ID from advanced API ipc_get_population(id = 12856213) # analysis with areas data frame ipc_get_population(id = 65508276) # analysis with groups data frame
# get all populations from the simplified API ipc_get_population() # get populations for specific analysis ID from advanced API ipc_get_population(id = 12856213) # analysis with areas data frame ipc_get_population(id = 65508276) # analysis with groups data frame