get_recorddata: Download structuredDataRecords data from the UNPD portal

Description Usage Arguments Details Examples

View source: R/GetInformation.R

Description

Download structuredDataRecords data from the UNPD portal

Usage

1
2
3
4
5
6
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):

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:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
## Not run: 

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

## End(Not run)

timriffe/DDSQLtools documentation built on Oct. 6, 2021, 5:34 p.m.