load_dhs: Load data from DHS

Description Usage Arguments Details Value Examples

Description

load_dhs (i) makes the catalog corresponding to the inputed profile's project, (ii) optionally filters it according to conditions on countries, years, and type of data, (iii) download the data file from the DHS server to disk and (iv) load these data files to the global environment.

Usage

1
load_dhs(profile, ..., output = getwd())

Arguments

profile

named character vector with fields data_name, your_email, your_password and your_project.

...

logical dplyr::filter predicates defined in terms of the variables in the catalog.

output

name of the directory in which the files downloaded from the DHS server should be saved.

Details

Of note, this function is supposed to be efficient in doing what it does. In particular, both the creation of the catalog and the downloading of data from the DHS server can be time consuming in that they query the DHS server. Furthermore, the loading of the data from disk to the global environment may also take time depending on the size and number of data files to load. Thus, each of these actions are preceded by checking whether they have previously done. If yes, they are not done again. If no, it also makes sure that it won't have to be done for a second call of the function. For example, if a catalog corresponding to the inputed profile's project already exist in the global environment, it won't be created again and this already existing catalog will be used instead. If such a catalog does not exist, then it will be created and used inside the function but also it will be saved in the global environment for potential future calls of the function on the same profile.

Value

This function does not return any thing and is used for its side effects, which are (i) creating the catalog corresponding to the inputed profile's project and saving it into the global environment, (ii) downloading the data to disk from the DHS server, and (iii) loading the downloaded data from disk to the global environment.

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
## Run the following call twice and see the differences in execution times:
## Not run: 
system.time(load_dhs(my_profile, year == 2015, country == "Tanzania", file_type == "KR"))
system.time(load_dhs(my_profile, year == 2015, country == "Tanzania", file_type == "KR"))

## End(Not run)

## Try deleting the data object and rerun:
## Not run: 
rm("TZKR7AFL")
system.time(load_dhs(my_profile, year == 2015, country == "Tanzania", file_type == "KR"))

## End(Not run)

## Try deleting the data file and rerun:
## Not run: 
file.remove("TZKR7AFL.rds")
system.time(load_dhs(my_profile, year == 2015, country == "Tanzania", file_type == "KR"))

## End(Not run)

## Try deleting the catalog and rerun:
## Not run: 
rm("my_profile_catalog")
system.time(load_dhs(my_profile, year == 2015, country == "Tanzania", file_type == "KR"))

## End(Not run)

epix-project/mics documentation built on May 9, 2019, 5:01 a.m.