Commit f54fac98 authored by Miguel Guerrero's avatar Miguel Guerrero

Corrige descrições

parent 5b29f7cd
......@@ -59,7 +59,7 @@ path_descricoes <- file.path(
Sys.getenv("general"),
"Bases",
"NCM_sh1996_a_sh2022",
"NCMs_sh.xlsx"
"descricoes_ncm_sh.xlsx"
)
......@@ -172,61 +172,88 @@ write_parquet(correlacao_completa, "dados_gerados/dataset_naladi.parquet")
# Processa e organiza descrições NCM --------------------------------------
descricoes_por_sh <- read_excel(
path_descricoes,
guess_max = 1e5
) %>%
rename(
sh = grupo_sh
)
# obtem abas disponíveis
abas <- readxl::excel_sheets(path_descricoes)
# obtem nome da ultima aba
ultimo_sh <- abas[length(abas)]
# remove ultima aba
abas <- abas[-length(abas)]
append_descricoes <- function(aba) {
read_xlsx(path_descricoes, sheet = aba) %>%
mutate(
across(
everything(),
~if_else(is.na(.x), "", .x)
),
across(
everything(),
~str_replace(.x, "^- ", "-")
),
across(
everything(),
~str_replace(.x, "^-- ", "--")
),
) %>%
transmute(
codigoFormatado,
sh,
descricao = paste(
desc_pos,
desc_subpos5,
desc_subpos6,
desc_item,
desc_subitem,
sep = "\n"
)
) %>%
mutate(
descricao = str_replace_all(
descricao,
"\n\n\n\n\n|\n\n\n\n|\n\n\n|\n\n",
"\n"
)
) %>%
mutate(
descricao = str_remove(descricao, "\n$")
)
}
ultimo_sh <- descricoes_por_sh %>%
distinct(sh) %>%
pull(sh) %>%
max()
descricoes_por_sh <- purrr::map_dfr(
abas,
~ append_descricoes(.x)
) %>%
rename(ncm = codigoFormatado) %>%
mutate(sh = str_replace(sh, "SH", "NCM"))
descricoes_por_sh <- descricoes_por_sh %>%
# remove o ultimo sh, pois ha ncms que ja deixaram de existir
filter(sh != ultimo_sh) %>%
mutate(
ncm = paste0(
str_sub(ncm, 1, 4), ".",
str_sub(ncm, 5, 6), ".",
str_sub(ncm, 7, 8)
),
sh = paste("NCM", sh)
)
####################
# # obtem abas disponíveis
# abas <- readxl::excel_sheets(path_descricoes)
# # obtem nome da ultima aba
# ultimo_sh <- abas[length(abas)]
# # remove ultima aba
# abas <- abas[-length(abas)]
# append_descricoes <- function(aba) {
# read_xlsx(path_descricoes, sheet = aba) %>%
# mutate(
# across(
# everything(),
# ~if_else(is.na(.x), "", .x)
# ),
# across(
# everything(),
# ~str_replace(.x, "^- ", "-")
# ),
# across(
# everything(),
# ~str_replace(.x, "^-- ", "--")
# ),
# ) %>%
# transmute(
# codigoFormatado,
# sh,
# descricao = paste(
# desc_pos,
# desc_subpos5,
# desc_subpos6,
# desc_item,
# desc_subitem,
# sep = "\n"
# )
# ) %>%
# mutate(
# descricao = str_replace_all(
# descricao,
# "\n\n\n\n\n|\n\n\n\n|\n\n\n|\n\n",
# "\n"
# )
# ) %>%
# mutate(
# descricao = str_remove(descricao, "\n$")
# )
# }
# descricoes_por_sh <- purrr::map_dfr(
# abas,
# ~ append_descricoes(.x)
# ) %>%
# rename(ncm = codigoFormatado) %>%
# mutate(sh = str_replace(sh, "SH", "NCM"))
descricoes_atuais <-
......@@ -277,18 +304,18 @@ descricoes_por_sh <- descricoes_por_sh %>%
)
)
#####################################################
# ATENÇÃO: Solução provisória para descrições NCM ##
# Quando houver descrições para todas as NCMs ######
# remover o código abaixo ##########################
####################################################
descricoes_por_sh <- descricoes_por_sh %>%
mutate(descricao = if_else(
sh != "NCM 2022",
" ",
descricao
))
# #####################################################
# # ATENÇÃO: Solução provisória para descrições NCM ##
# # Quando houver descrições para todas as NCMs ######
# # remover o código abaixo ##########################
# ####################################################
#
# descricoes_por_sh <- descricoes_por_sh %>%
# mutate(descricao = if_else(
# sh != "NCM 2022",
# " ",
# descricao
# ))
descricoes_por_sh %>%
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment