Skip to content

Commit

Permalink
checked for new version release
Browse files Browse the repository at this point in the history
  • Loading branch information
sammo3182 committed Aug 28, 2023
1 parent fa7ea2d commit b7d7aba
Show file tree
Hide file tree
Showing 2 changed files with 636 additions and 390 deletions.
169 changes: 114 additions & 55 deletions vignettes/regioncode-vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,45 @@
knitr::opts_chunk$set(message = FALSE, warning = FALSE)

if(!require(regioncode)) install.packages("regioncode")
library(regioncode)
library(tidyverse)

## ----code2code----------------------------------------------------------------
library(regioncode)

data("corruption")

# Original 2019 version
corruption$prefecture_id

# 1989 version
temp <- regioncode(data_input = corruption$prefecture_id,
convert_to = "code", # default set
# Conversion to the 1989 version
regioncode(data_input = corruption$prefecture_id,
convert_to = "code", # default setting
year_from = 2019,
year_to = 1989)

# tibble(
# code2019 = corruption$prefecture_id,
# code1989 = regioncode(data_input = corruption$prefecture_id,
# convert_to = "code", # default set
# year_from = 2019,
# year_to = 1989),
# name1989 = regioncode(data_input = corruption$prefecture_id,
# convert_to = "name", # default set
# year_from = 2019,
# year_to = 1989)
# )
# Comparison
tibble(
code2019 = corruption$prefecture_id,
code1989 = regioncode(data_input = corruption$prefecture_id,
convert_to = "code", # default setting
year_from = 2019,
year_to = 1989),
name2019 = regioncode(data_input = corruption$prefecture_id,
convert_to = "name", # default setting
year_from = 2019,
year_to = 2019),
name1989 = regioncode(data_input = corruption$prefecture_id,
convert_to = "name", # default setting
year_from = 2019,
year_to = 1989)
)

## ----code2name----------------------------------------------------------------
# The original name
corruption$prefecture
# Original name
tibble(
id = corruption$prefecture_id,
name = corruption$prefecture
)

# Codes to name

regioncode(data_input = corruption$prefecture_id,
convert_to = "name",
year_from = 2019,
Expand All @@ -48,76 +53,130 @@ regioncode(data_input = corruption$prefecture,
year_to = 2019)

# Name to name of a different year

regioncode(data_input = corruption$prefecture,
convert_to = "name",
year_from = 2019,
year_to = 1989)

## ----incomplete_name----------------------------------------------------------
# Full, official names
# Original full names
corruption$prefecture

regioncode(data_input = corruption$prefecture,
# Conversion to incomplete names in 1989
fake_incomplete <- regioncode(data_input = corruption$prefecture,
convert_to = "name",
year_from = 2019,
year_to = 1989,
incomplete_name = "to")
fake_incomplete

## ----2area--------------------------------------------------------------------
regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to="area")

## ----language_zone------------------------------------------------------------
regioncode(data_input = corruption$prefecture,
# Conversion to full names in 2008
fake_full <- regioncode(data_input = fake_incomplete,
convert_to = "name",
year_from = 1989,
year_to = 2008,
incomplete_name = "from")
fake_full

## ----municipality-------------------------------------------------------------
names_municipality <- c("北京市", # Beijing, a municipality
"海淀区", # A district of Beijing
"上海市", # Shanghai, a municipality
"静安区", # A district of Shanghai
"济南市") # A prefecture of Shandong

# When `zhixiashi` is FALSE, only the districts are recognized
regioncode(data_input = names_municipality,
year_from = 2019,
year_to = 1989,
to_dialect = "dia_group")
year_to = 2019,
convert_to = "code",
zhixiashi = FALSE)

regioncode(data_input = corruption$prefecture,
# When `zhixiashi` is TRUE, municipalities are recognized
regioncode(data_input = names_municipality,
year_from = 2019,
year_to = 1989,
to_dialect = "dia_sub_group")
year_to = 2019,
convert_to = "code",
zhixiashi = TRUE)

## ----rank---------------------------------------------------------------------
tidyr::tibble(
preference = corruption$prefecture,
rank = regioncode(data_input = corruption$prefecture,
year_from = 2011,
tibble(
city = corruption$prefecture,
rank1989 = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to="rank")
convert_to="rank"),
rank2014 = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 2014,
convert_to = "rank")
)


## ----pinyin-------------------------------------------------------------------
regioncode(data_input = corruption$prefecture,
tibble(
city = corruption$prefecture,
cityPY = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to="name",
to_pinyin=TRUE
)

regioncode(data_input = corruption$prefecture,
convert_to = "name",
to_pinyin = TRUE
),
cityIncomplete = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to="name",
convert_to = "name",
incomplete_name = "to",
to_pinyin=TRUE
to_pinyin = TRUE
),
areaPY = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to = "area",
to_pinyin = TRUE
)
)

regioncode(data_input = corruption$prefecture,
# Regions with special spelling
regioncode(data_input = c("山西", "陕西", "内蒙古", "香港", "澳门"),
year_from = 2019,
year_to = 1989,
convert_to="area",
to_pinyin=TRUE
year_to = 2008,
convert_to = "name",
incomplete_name = "both",
province = TRUE,
to_pinyin = TRUE
)

## ----provinces----------------------------------------------------------------
regioncode(data_input = corruption$province_id,
tibble(
province = corruption$province_id,
prov_name = regioncode(data_input = corruption$province_id,
convert_to = "name",
year_from = 2019,
year_to = 1989,
province = TRUE),
prov_abbre = regioncode(data_input = corruption$province_id,
convert_to = "codeToabbre",
year_from = 2019,
year_to = 1989,
province = TRUE)
)

## ----2area--------------------------------------------------------------------
regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
convert_to = "area")

## ----language_zone------------------------------------------------------------
tibble(
city = corruption$prefecture,
dialectGroup = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
to_dialect = "dia_group"),
dialectSubGroup = regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
to_dialect = "dia_sub_group")
)

Loading

0 comments on commit b7d7aba

Please sign in to comment.