/
retrieve_data.R
102 lines (100 loc) · 6.3 KB
/
retrieve_data.R
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_indicator <- function(IndicatorIDs, ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
set_config(config(ssl_verifypeer = 0L))
fingertips_data <- data.frame()
for (i in seq_len(length(IndicatorIDs))) {
IndicatorID <- IndicatorIDs[i]
for (ChildAreaTypeID in ChildAreaTypeIDs) {
for (ParentAreaTypeID in ParentAreaTypeIDs) {
if (missing(ProfileIDs)){
dataurl <- paste0(path,
sprintf("all_data/csv/by_indicator_id?indicator_ids=%s&child_area_type_id=%s&parent_area_type_id=%s",
IndicatorID, ChildAreaTypeID, ParentAreaTypeID),
"&include_sortable_time_periods=yes")
} else {
ProfileID <- ProfileIDs[i]
if (is.na(ProfileID)) {
dataurl <- paste0(path,
sprintf("all_data/csv/by_indicator_id?indicator_ids=%s&child_area_type_id=%s&parent_area_type_id=%s",
IndicatorID,ChildAreaTypeID,ParentAreaTypeID),
"&include_sortable_time_periods=yes")
} else {
dataurl <- paste0(path,
sprintf("all_data/csv/by_indicator_id?indicator_ids=%s&child_area_type_id=%s&parent_area_type_id=%s&profile_id=%s",
IndicatorID, ChildAreaTypeID, ParentAreaTypeID, ProfileID),
"&include_sortable_time_periods=yes")
}
}
fingertips_data <- rbind(dataurl %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
col_types = types),
fingertips_data)
}
}
}
return(fingertips_data)
}
#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_domain <- function(DomainIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
set_config(config(ssl_verifypeer = 0L))
fingertips_data <- data.frame()
for (DomainID in DomainIDs) {
for (ChildAreaTypeID in ChildAreaTypeIDs) {
for (ParentAreaTypeID in ParentAreaTypeIDs) {
dataurl <- paste0(path,
sprintf("all_data/csv/by_group_id?child_area_type_id=%s&parent_area_type_id=%s&group_id=%s",
ChildAreaTypeID,ParentAreaTypeID,DomainID),
"&include_sortable_time_periods=yes")
fingertips_data <- rbind(dataurl %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
col_types = types),
fingertips_data)
}
}
}
return(fingertips_data)
}
#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_profile <- function(ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
set_config(config(ssl_verifypeer = 0L))
fingertips_data <- data.frame()
for (ProfileID in ProfileIDs) {
for (ChildAreaTypeID in ChildAreaTypeIDs) {
for (ParentAreaTypeID in ParentAreaTypeIDs) {
dataurl <- paste0(path,
sprintf("all_data/csv/by_profile_id?child_area_type_id=%s&parent_area_type_id=%s&profile_id=%s",
ChildAreaTypeID,ParentAreaTypeID,ProfileID),
"&include_sortable_time_periods=yes")
fingertips_data <- rbind(dataurl %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
col_types = types),
fingertips_data)
}
}
}
return(fingertips_data)
}