knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

taitratools

Taitra Tools package gather all useful helper functions.

Most function in taitratools are prefix with tt_.

You can list all source path with tt_ls() funciton, read data with tt_read_table() or tt_read_mof() ...

# install.packages("devtools")
devtools::install_github("chinhungtseng/taitratools")

Example

Get data source path

library(taitratools)

tt_ls()

Read data

path <- tt_get_path("PATH_AREA")
path

area_tbl <- tt_read_table(path)
head(area_tbl)

This is a basic example which shows you how to read data from MOF, if you want to read data with past year, you can set period = N

# Default is `export` and `usd`
mof_data <- tt_vroom_mof("2019-01", "2019-02", period = 1, direct = "export", money = "usd", dep_month_cols = TRUE)
head(mof_data)

Data Transform

Industry data transforming

# industry_type => "all_industry", "industry21", "version1", "version2"
mof_data %>% 
  tt_bind_industry(sub = 8, col_more = TRUE, industry_type = "industry21", verbose = FALSE) %>% 
  head(5)
mof_industry_data <- mof_data %>% 
  tt_industry_grouped_sum(industry_type = "industry21", sub = 6, verbose = FALSE)

str(mof_industry_data)
head(mof_industry_data$data, 5)

Area data transforming

Adding a area column

mof_industry_data$data %>% tt_bind_area() %>% head(5)

Append area data

mof_industry_data$data %>% tt_append_area() %>% head(5)

Append only world data

mof_industry_data$data %>% tt_append_global() %>% head(5)

Others

grouped data and sum the value

mof_data %>% tt_grouped_sum(country, year, by = "value") %>% head(5)
mof_data %>% tt_grouped_sum(year, month, by = "count") %>% head(5)
mof_data %>%
  tt_bind_industry(industry_type = "industry21", verbose = FALSE) %>% 
  tt_grouped_sum(industry, country, year, by = "weight") %>% head(5)


chinhungtseng/taitratools documentation built on Jan. 11, 2021, 8:33 p.m.