ilo R tools

This R package provides tools to manipulate ILO Data from Statistics department database.

For contact information and source code, see the github page

Available tools

Installation

Release version (not yet available):

# install.packages("ilo")

Development version:

require(devtools)
install_github("dbescond/ilo")

Overall, the ilo package includes the following functions:

require(ilo)
as.data.frame(ls("package:ilo")) 

check tutorials

help_ilo()

Download and Finding data

Function init_ilo() download ilo Datasets and prepare setting. return dataframe of the available file init_ilo(update) force the update

init_ilo()

setting are available in 3 languages, English, french and spanish 'en', 'fr', 'es'} the default is 'en'

init_ilo(update, lang = 'fr')

Function close_ilo() close the clusters and close_ilo(delete) close and delete the entire repository

close_ilo()

By default Database are store under your '.../'user'/AppData/Local/ILO/', lazyLoad rdb files are there.

Then data are store by collection and freqency:

ilo$segment 

get codelist availability

names(ilo$code) %>% sort

Get and filter data

Function get_ilo() collect data on one or several collection / freq, by default collection = 'YI', freq = 'A'

# get monthly indicator (from STI collection) of Canada (geo = 'CAN')
get_ilo(collection = 'STI', freq = 'M', ref_area = 'CAN') 
# get quarterly data (from ST collection) for unemployment rate (indicator = 'UNE_DEAP_RT')
get_ilo(collection = 'STI', freq = 'Q', ref_area = 'CAN', Query = "filter(indicator %in% 'UNE_DEAP_SEX_AGE_RT')")

Function switch_ilo() label data for one or several variables

# label all variables and back in a wide style

Mydata <- get_ilo(collection = 'STI', freq = 'M', ref_area = 'ALB') 
Mydata %>% switch_ilo()
# label only indicator
Mydata %>% switch_ilo(indicator)

Function filter_ilo() seach character string inside one variable

Mydata <- get_ilo(collection = 'STI', freq = 'Q', ref_area = 'FRA') %>% switch_ilo(classif1, indicator) 
Mydata %>% filter_ilo(classif1 = 'Aggregate age bands')
Mydata %>% filter_ilo(indicator = 'Unemployment')

Check your data in with html tools (only for small dataset ...)

get_ilo(collection = 'STI', freq = 'Q', ref_area = 'ALB') %>% 
  switch_ilo() %>% 
  view_ilo() 

Advanced manipulation

This exercice show us how to make a special query ............. to do

LAST <- full_join(  
    get_ilo( query = "  select(ref_area, time, source) %>% 
                                    filter(str_sub(time,1,4) > '2013')", 
                       collection = 'STI', 
                       freq = 'Q', 
                       package= 'stringr') %>% 
        group_by(ref_area, time, source) %>%
        summarise(n = n()) %>% 
        ungroup() %>%
        spread(time, n) %>% filter(!substr(source,1,3) %in% 'GA:') 
        ,
# add the ref_area weight from collection = 'ILOEST' indicator %in% EAP_2EAP_NB   
      get_ilo( query = "    filter( as.character(time) %in% '2014', 
                                      indicator %in% 'EAP_2EAP_SEX_AGE_NB', 
                                      sex %in% 'SEX_T',
                          classif1 %in% 'AGE_5YRBANDS_TOTAL') %>%
                                  select(ref_area, obs_value)", 
                   collection = 'ILOEST', 
                   freq = 'A') %>% mutate(obs_value = round(obs_value, 0)) %>% 
      rename(EAP2014 = obs_value)
, by = 'ref_area') %>% 
select(ref_area, source, EAP2014, starts_with('20')) %>%
arrange(desc(EAP2014)) %>% # sort by the weight
mutate(iso3 = ref_area) %>% switch_ilo(ref_area)

Save your work

Save your data in xls (allowed multiple dataset)

X <- get_ilo(collection = 'STI', freq = 'Q', ref_area = 'ALB')
Y <- get_ilo(ref_area = 'ALB') 

save_ilo(X = 'InSTI', Y = 'InYI')
save_ilo(X,Y)

Save your data in csv format

X <- get_ilo(collection = 'STI', freq = 'Q', ref_area = 'ALB')
save_ilo(X, format = 'csv')

Save your data in csv ilo delete format

X <- get_ilo(collection = 'STI', freq = 'Q', ref_area = 'ALB')
save_ilo(X, format = 'del')

Save your data in xls revision format (produce 2 sheets one for revision on for deletion)

X <- get_ilo(collection = 'STI', freq = 'Q', ref_area = 'ALB')
save_ilo(X, format = 'rev')

Session info

This tutorial was created with

sessionInfo()


dbescond/ilo documentation built on Dec. 10, 2019, 10:01 a.m.