Skip to content

Commit

Permalink
fixed the non-ASCII code
Browse files Browse the repository at this point in the history
  • Loading branch information
sammo3182 committed Feb 2, 2024
1 parent ff05c1e commit 7c0c1ee
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 87 deletions.
44 changes: 22 additions & 22 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
library(regioncode)
library(regioncode)
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
# Full, official names
corruption$prefecture
regioncode(data_input = corruption$prefecture,
convert_to = "name",
year_from = 2019,
year_to = 1989,
incomplete_name = "to")
regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1999,
convert_to="area")
library(regioncode)
library(regioncode)
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
to_dialect = "dia_group")
regioncode(data_input = corruption$prefecture,
year_from = 2019,
year_to = 1989,
to_dialect = "sub_dia_group")
Expand Down Expand Up @@ -510,3 +488,25 @@ regioncode(data_input = corruption$prefecture_id,
convert_to = "name", # default setting
year_from = 2019,
year_to = 1989)
?switch
?case_when
`%>%`
?`%>%`
library(regioncode)
?bind_rows
library(regioncode)
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
if(!require(regioncode)) install.packages("regioncode")
library(regioncode)
library(tidyverse)
# Regions with special spelling
regioncode(data_input = c("山西", "陕西", "内蒙古", "香港", "澳门"),
year_from = 2019,
year_to = 2008,
convert_to = "name",
incomplete_name = TRUE,
province = TRUE,
to_pinyin = TRUE
)
?ends_with
?pull
4 changes: 1 addition & 3 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
/home/sammo3182/Seafile/WW_research/01_Research/R_package/regioncode/DESCRIPTION="9D98CAD9"
/home/sammo3182/Seafile/WW_research/01_Research/R_package/regioncode/R/regioncode.R="999BE19B"
/home/sammo3182/Seafile/WW_research/01_Research/R_package/regioncode/vignettes/regioncode-vignette.Rmd="B320A102"
/home/sammo3182/Seafile/WW_research/01_Research/R_package/regioncode/vignettes/regioncode-vignette.Rmd="04B918E1"
62 changes: 30 additions & 32 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
Package: regioncode
Title: Convert Region Names and Division Codes of China Over Years
Version: 0.1.2
Authors@R:
c(person(given = "Yue",family = "Hu",role = c("aut","cre"), email = "yuehu@tsinghua.edu.cn"),
person(given = "Xinyi",family = "Ye",role = c("aut"), email = "yexy23@mails.tsinghua.edu.cn"),
person(given = "Yufei",family = "Sun",role = c("aut"), email = "sunyf20@mails.tsinghua.edu.cn"),
person(given = "Wenquan",family = "Wu",role = c("aut"), email = "gohuntsuan@gmail.com"))
Author: Yue Hu [aut, cre],
Xinyi Ye [aut],
Yufei Sun [aut],
Wenquan Wu [aut]
Maintainer: Yue Hu <yuehu@tsinghua.edu.cn>
Description: A tool to conquer the difficulties to convert various region names and administration division codes of Chinese regions. The current version enables seamlessly converting Chinese regions' formal names, common-used names, and codes between each other at the city level from 1986 to 2019.
License: MIT + file LICENSE
Encoding: UTF-8
BugReports: https://github.com/sammo3182/regioncode/issues
Depends:
R(>= 3.6.0)
Imports:
dplyr,
pinyin,
tidyverse
Suggests:
testthat (>= 3.0.0),
rmarkdown,
knitr
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Config/testthat/edition: 3
VignetteBuilder: knitr
Package: regioncode
Title: Convert Region Names and Division Codes of China Over Years
Version: 0.1.2
Authors@R:
c(person(given = "Yue",family = "Hu",role = c("aut","cre"), email = "yuehu@tsinghua.edu.cn"),
person(given = "Xinyi",family = "Ye",role = c("aut"), email = "yexy23@mails.tsinghua.edu.cn"),
person(given = "Yufei",family = "Sun",role = c("aut"), email = "sunyf20@mails.tsinghua.edu.cn"),
person(given = "Wenquan",family = "Wu",role = c("aut"), email = "gohuntsuan@gmail.com"))
Author: Yue Hu [aut, cre],
Xinyi Ye [aut],
Yufei Sun [aut],
Wenquan Wu [aut]
Maintainer: Yue Hu <yuehu@tsinghua.edu.cn>
Description: A tool to conquer the difficulties to convert various region names and administration division codes of Chinese regions. The current version enables seamlessly converting Chinese regions' formal names, common-used names, and codes between each other at the city level from 1986 to 2019.
License: MIT + file LICENSE
Encoding: UTF-8
BugReports: https://github.com/sammo3182/regioncode/issues
Depends:
R(>= 3.6.0)
Imports:
dplyr,
pinyin
Suggests:
rmarkdown,
knitr
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Config/testthat/edition: 3
VignetteBuilder: knitr
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
export(regioncode)
import(dplyr)
import(pinyin)
import(tidyverse)
39 changes: 12 additions & 27 deletions R/regioncode.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
#'
#' @returns The function returns a character or numeric vector depending on what method is specified.
#'
#' @import dplyr
#' @import pinyin
#' @import tidyverse
#' @import dplyr
#'
#' @examples
#'
Expand Down Expand Up @@ -307,7 +306,7 @@ regioncode <- function(data_input,
region_province <- region_province[, order(colnames(region_province))]


region_data<- bind_rows(region_zhixiashi, region_province)
region_data <- bind_rows(region_zhixiashi, region_province)
}
}
}
Expand All @@ -333,31 +332,17 @@ regioncode <- function(data_input,
pull(!!year_to)

# Because '2pinyin' can not be used as a variable name

if (to_pinyin) {
if (is.character(data_output)) {
data_output <-
ifelse(
data_output == "\\u9655\\u897f", "shaan_xi",
ifelse(
data_output == "\\u9655\\u897f\\u7701", "shaan_xi_sheng",
ifelse(
data_output == "\\u5185\\u8499\\u53e4", "inner_mongolia",
ifelse(
data_output =="\\u897f\\u85cf", "tibet",
ifelse(
data_output == "\\u6fb3\\u95e8", "macao",
ifelse(
data_output == "\\u9999\\u6e2f", "hong_kong",
py(char = data_output,
dic = pydic(method = "toneless", dic = "pinyin2")
)
)
)
)
)
)
)
}
data_output <- case_when(
substr(data_output, start = 1, stop = 2) == "\u9655\u897f" ~ "shaan_xi",
substr(data_output, start = 1, stop = 2) == "\u5185\u8499" ~ "inner_mongolia",
substr(data_output, start = 1, stop = 2) == "\u897f\u85cf" ~ "tibet",
substr(data_output, start = 1, stop = 2) == "\u6fb3\u95e8" ~ "macao",
substr(data_output, start = 1, stop = 2) == "\u9999\u6e2f" ~ "hong_kong",
TRUE ~ py(char = substr(data_output, start = 1, stop = 2), dic = pydic(method = "toneless", dic = "pinyin2"))
)
}

return(data_output) }

4 changes: 2 additions & 2 deletions vignettes/regioncode-vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ knitr::opts_chunk$set(message = FALSE, warning = FALSE)
if(!require(regioncode)) install.packages("regioncode")
library(regioncode)
library(tidyverse)
library(dplyr)
```

The term "city" in China encompasses a multifaceted concept.
Expand Down Expand Up @@ -154,7 +154,7 @@ fake_incomplete <- corruption$prefecture
index_incomplete <- sample(seq(length(corruption$prefecture)), 7)
fake_incomplete[index_incomplete] <- fake_incomplete[index_incomplete] |>
str_sub(end = 2)
substr(start = 1, stop = 2)
fake_incomplete
Expand Down

0 comments on commit 7c0c1ee

Please sign in to comment.