Download structuredDataRecords data from the UNPD portal

get_recorddata(
  save_file = FALSE,
  verbose = TRUE,
  collapse_id_name = FALSE,
  ...
)

Arguments

save_file

Logical. Choose whether or not to save the data in an external .Rdata file in the working directory. Default: FALSE.

verbose

Whether to print the translated query from strings to digits for faster queries. By default set to TRUE.

collapse_id_name

A logical to whether collapse all ID-Name columns into a single haven_labelled column. Default set to FALSE. See details for more information.

...

Other arguments that might define the path to data. All arguments accept a numeric code which is interpreted as the code of the specific product requested. Alternatively, you can supply the equivalent product name as a string which is case insensitive (see examples). Handle with care, this is important! For a list of all options available, see the parameters for each endpoint at https://popdiv.dfs.un.org/Demodata/swagger/ui/index#/

Details

get_recorddata directly queries the endpoint structuredDataRecords. For a list of all options available for this endpoint, see the parameters for each endpoint at http://24.239.36.16:9654/un3/swagger/ui/index#!/StructuredData/StructuredData_GetStructuredDataRecords

get_recorddata allows the user to supply string names for all arguments that have equivalent get_* functions. For example, get_iitypes for indicatorIds. The string used for all of these arguments should be the one from the column Name in the response from the get_* functions.

By default, all results exclude columns related to the uncertainty of the values requested (StandardErrorValue, ConfidenceInterval, etc...). By setting the argument includeUncertainty = TRUE, the uncertainty fields will be included in the final data frame.

Once the data is read from the API, some transformations are applied. If collapse_id_name is set to TRUE, all of these columns are merged with their exact ID pairs (such that only the Name columns are kept and their ID pair are assigned as labels):

  • Columns AreaName, DataReliabilityName, SubGroupName, DataStatusName, DataTypeName, DataTypeGroupName, IndicatorName, LocName, LocAreaTypeName, LocTypeName, ModelPatternName, ModelPatternFamilyName, PeriodGroupName, PeriodTypeName, RegName, SexName, StatisticalConceptName, SubGroupTypeName are converted to labelled factors with labelled

For an example to understand better how to exploit this feature, see the vignette section 'Identifying ID and Names of values'.

Regardless of the collapse_id_name value, these transformations are applied:

  • TimeStart and TimeEnd are returned with format 'DD/MM/YYYY'

Examples

if (FALSE) {

#  You can provide all strings, all codes, or a combination of both
Y <- get_recorddata(
  dataProcessTypeIds = "Census",
  indicatorTypeIds = 8, # and support numeric of string names
  locIds = "egypt", # all arguments are case insensitive
  locAreaTypeIds = "Whole area",
  subGroupIds = "Total or All groups",
  isComplete = "Abridged"
)

head(Y)

# Same thing only with codes
X <- get_recorddata(
  dataProcessTypeIds = 2, # Census
  indicatorTypeIds = 8, # Population by age and sex - abridged
  locIds = 818, # Egypt
  locAreaTypeIds = 2, # Whole area
  subGroupIds = 2, # Total or All groups
  isComplete = 0
) # Age Distribution: Abridged

head(X)

# Same thing but limited to DataSourceYears
X <- get_recorddata(
  dataProcessTypeIds = 2,
  indicatorTypeIds = 8,
  locIds = 818,
  locAreaTypeIds = 2,
  subGroupIds = 2,
  isComplete = 0,
  dataSourceYears = 1980
)

head(X)

# Same thing but limited to DataSourceShortNames and including the uncertainty
X <- get_recorddata(
  dataProcessTypeIds = 2,
  indicatorTypeIds = 8,
  locIds = 818,
  locAreaTypeIds = 2,
  subGroupIds = 2,
  isComplete = 0,
  dataSourceShortNames = "OECD 1980",
  includeUncertainty = TRUE
)

head(X)

# You can also request the Name-ID pairs of columns to be collapsed
# to only the Name columns and ID pair is assigned as a label
X <- get_recorddata(
  dataProcessTypeIds = 2,
  indicatorTypeIds = 8,
  locIds = 818,
  locAreaTypeIds = 2,
  subGroupIds = 2,
  isComplete = 0,
  dataSourceShortNames = "OECD 1980",
  includeUncertainty = TRUE,
  collapse_id_name = TRUE
)

# Some of the collapsed columns:
head(x[, c("IndicatorName", "LocTypeName")])
}