-
Notifications
You must be signed in to change notification settings - Fork 0
/
PFW_fix.R
59 lines (43 loc) · 1.72 KB
/
PFW_fix.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
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Objective: PFW fix to cache
# Author: Diana C. Garcia Rojas
# Dependencies: The World Bank
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Creation Date: June 2024
# References:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Remove surveys that are not in PFW ---------
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# NOTE: This piece of code was taken from _cache_loading_saving.R file
### remove all the surveyar that are not available in the PFW ----
svy_in_pfw <- dl_aux$pfw[, link]
pattern <- "([[:alnum:]]{3}_[[:digit:]]{4}_[[:alnum:]\\-]+)(.*)"
cache_names <-
names(cache) |>
gsub(pattern = pattern,
replacement = "\\1",
x = _)
#names(cache_dir) <- cache_ids
cache_dir_names <-
cache_ids |>
gsub(pattern = pattern,
replacement = "\\1",
x = _)
to_drop_cache <- which(!cache_names %in% svy_in_pfw)
to_drop_cache_dir <- which(!cache_dir_names %in% svy_in_pfw)
cache[to_drop_cache] <- NULL
if (length(to_drop_cache_dir) > 0)
cache_dir <- cache_dir[-to_drop_cache_dir]
cache_inventory[,
cache_names := gsub(pattern = pattern,
replacement = "\\1",
x = cache_id)]
cache_inventory <- cache_inventory[cache_names %chin% svy_in_pfw]
cache_ids <- get_cache_id(cache_inventory)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## notify that lenghts are different ---
if (length(cache) != length(cache_dir)) {
cli::cli_abort("Lengths of cache list ({length(cache)}) and cache directory
({length(cache_dir)}) are not the same")
}