Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug quando vai pegar mais de um demontrativo #8

Closed
GiovanniChiodini opened this issue Jan 18, 2023 · 11 comments
Closed

Bug quando vai pegar mais de um demontrativo #8

GiovanniChiodini opened this issue Jan 18, 2023 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@GiovanniChiodini
Copy link

Quando realizo o código para pegar os DRE do ano "x" ao "y" ele baixa os arquivos gerais do ano "x" ao "y" na pasta "gdfpd2_cache".

Quando em sequencia peço para baixar os BPA de uma empresa por exemplo ele da o erro a seguir:

File already existsError in if (dl_size == current_size) { :
missing value where TRUE/FALSE needed

Então tenho que limpar para baixar de novo, sendo que anteriormente (em versões mais antigas), o código pegava o arquivo já se ele tivesse baixado automaticamente

@msperlin
Copy link
Owner

Oi Giovanni,

Tens um código que eu possa repclicar o erro? Isso facilita eu verificar aqui..

@GiovanniChiodini
Copy link
Author

Por exemplo essa parte do codigo

# CODE POUR EXPORTER LE BILAN ET LE DRE DE MANI?RE AUTONOME

pacotes<-c("tryCatchLog","xlsx","httr","jsonlite","RPostgreSQL","RODBC","reshape","readbulk","plotly","lubridate","readxl","HH","sqldf","dplyr","data.table","arules","dgof","pROC","Information","InformationValue","stringr","tree","rpart","Amelia","ggplot2","descr","scales","ggthemes","ztable","tibble","tidyr","RCurl","purrr") 
# REMOVE THE COMMENT BELOW TO INSTALL THE PACKAGES
# install.packages(pacotes)
# LOADING ALL PACKAGES
lapply(pacotes, require, character.only = TRUE)

# install pkg if not found
if (!require(devtools)) install.packages("devtools")
if (!require(GetDFPData2)) devtools::install_github("msperlin/GetDFPData2") 


# load pkg
library(GetDFPData2)

# get companies codes and names
df_info <- get_info_companies()
co.cd_cvm = 21091
nome_empresa = "DXCO"
# set input options
my_ids <- c(co.cd_cvm) 
hoje <- as.Date(Sys.Date())
first_year  <- lubridate::year(as.Date("2016-01-01"))
last_year   <- lubridate::year(hoje)-3

# get data using get_dfp_data
# This can take a while since the local data is not yet cached..

# extracting the assets
ATIVO <- as.data.frame(get_dfp_data(companies_cvm_codes = my_ids,
                                    use_memoise = FALSE,
                                    clean_data = TRUE,
                                    first_year = first_year, 
                                    last_year  = last_year,
                                    #type_docs = c("BPA", "BPP", "DRE"), 
                                    type_docs = c("BPA"),
                                    #type_format = c("con","ind")
                                    type_format = "con"))

colnames(ATIVO) = sub('.*\\.', '', colnames(ATIVO))

ATIVO <- ATIVO %>% 
  dplyr::select(DT_REFER,CD_CONTA,DS_CONTA,VL_CONTA)


unlink("C:/Users/giova/OneDrive/Documentos/VALUATION/01. Code/gdfpd2_cache/DFP_zip_files/*")


# extracting the liabilities
PASSIVO <- as.data.frame(get_dfp_data(companies_cvm_codes = my_ids,
                                      use_memoise = FALSE,
                                      clean_data = TRUE,
                                      first_year = first_year, 
                                      last_year  = last_year,
                                      #type_docs = c("BPA", "BPP", "DRE"), 
                                      type_docs = c("BPP"),
                                      #type_format = c("con","ind")
                                      type_format = "con"))

colnames(PASSIVO) = sub('.*\\.', '', colnames(PASSIVO))

PASSIVO <- PASSIVO %>% 
  dplyr::select(DT_REFER,CD_CONTA,DS_CONTA,VL_CONTA)

@msperlin
Copy link
Owner

Giovanni, estás usando a versão mais nova do pacote? Podes atualizar ocm update.packages()

@msperlin
Copy link
Owner

Rodei o código aqui e funcionou sem problema..

@Sidonesio
Copy link

Obtive a mesma mensagem de erro:

Dowloading dfp_cia_aberta_2012.zip
File already existsError in purrr::map():
ℹ In index: 1.
Caused by error in if (dl_size == current_size) ...:
! missing value where TRUE/FALSE needed
Run rlang::last_trace() to see where the error occurred.

Código abaixo:

clean workspace

rm(list = ls())

delete graphics

graphics.off()

unload all packages

lapply(names(sessionInfo()$otherPkgs), function(pkgs)
detach(
paste0('package:', pkgs),
character.only = T,
unload = T,
force = T
))

install pacman if it is not installed

if (!require("pacman")) install.packages("pacman")

install packages if they are not installed

and load them

p_load(
GetDFPData2,
tidyverse,
lubridate,
janitor,
scales
)

return information about B3 companies

df_info <-
get_info_companies() |>
clean_names()

take a look at data

df_info
glimpse(df_info)

search for a company

df <-
search_company('banco do brasil') |>
clean_names()

take a look at data

df
glimpse(df)

get company code

code <-
df |>
pull(cd_cvm)
code

download and read DFP datasets

data <- get_dfp_data(
companies_cvm_codes = code,
first_year = 2012,
last_year = year(Sys.Date()),
type_docs = c("BPA","BPP","DRE"),
type_format = "con",
clean_data = TRUE,
use_memoise = FALSE,
cache_folder = "gdfpd2_cache",
do_shiny_progress = FALSE
)

Session Info:

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8 LC_CTYPE=Portuguese_Brazil.utf8 LC_MONETARY=Portuguese_Brazil.utf8
[4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] scales_1.2.1 janitor_2.2.0 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.1
[7] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0
[13] GetDFPData2_0.6.2 pacman_0.5.1

loaded via a namespace (and not attached):
[1] pillar_1.9.0 compiler_4.2.3 bitops_1.0-7 tools_4.2.3 lifecycle_1.0.3 gtable_0.3.3
[7] timechange_0.2.0 pkgconfig_2.0.3 rlang_1.1.0 cli_3.6.1 rstudioapi_0.14 curl_5.0.0
[13] httr_1.4.5 withr_2.5.0 xml2_1.3.3 generics_0.1.3 vctrs_0.6.2 hms_1.1.3
[19] grid_4.2.3 tidyselect_1.2.0 glue_1.6.2 snakecase_0.11.0 R6_2.5.1 fansi_1.0.4
[25] selectr_0.4-2 tzdb_0.3.0 magrittr_2.0.3 rvest_1.0.3 colorspace_2.1-0 utf8_1.2.3
[31] stringi_1.7.12 RCurl_1.98-1.12 munsell_0.5.0

@Sidonesio
Copy link

Pode me ajudar por gentileza, professor?

@msperlin
Copy link
Owner

Claro.

Estás usando a versão atualizada do pacote? Caso em dúvida:

  1. execute update.packages() no prompt
  2. reinicie sua sessão do R
  3. rode o código

Se ainda tiver problemas, copia e cola o código (apenas) aqui que vou testar.

@Sidonesio
Copy link

Sim, professor. Já havia atualizado os pacotes. Acabei de atualizar o R também. Reiniciei, rodei de novo, deu a mesma mensagem de erro. Código abaixo:

rm(list = ls())

graphics.off()

lapply(names(sessionInfo()$otherPkgs), function(pkgs)
detach(
paste0('package:', pkgs),
character.only = T,
unload = T,
force = T
))

if (!require("pacman")) install.packages("pacman")

p_load(
GetDFPData2,
tidyverse,
lubridate,
janitor,
scales
)

df_info <-
get_info_companies() |>
clean_names()

df_info
glimpse(df_info)

df <-
search_company('banco do brasil') |>
clean_names()

df
glimpse(df)

code <-
df |>
pull(cd_cvm)
code

data <- get_dfp_data(
companies_cvm_codes = code,
first_year = 2012,
last_year = year(Sys.Date()),
type_docs = c("BPA","BPP","DRE"),
type_format = "con",
clean_data = TRUE,
use_memoise = FALSE,
cache_folder = "gdfpd2_cache",
do_shiny_progress = FALSE
)

Obrigado pelo retorno.

@msperlin
Copy link
Owner

Bom dia @Sidonesio

O problema só ocorre no windows, por isso que eu não consegua reproduzir. Vou arrumar assim que puder.
No meio tempo, use o memoise ( use_memoise = TRUE), e o código vai funcionar normalmente.

obrigado.

@msperlin msperlin self-assigned this Apr 24, 2023
@msperlin msperlin added the bug Something isn't working label Apr 24, 2023
msperlin added a commit that referenced this issue Apr 24, 2023
@msperlin
Copy link
Owner

Arrumado. Reinstale com devtools::install_gitbhu() e rode novamente. Me diga como foi.

@Sidonesio
Copy link

Deu certo, professor. Muitíssimo obrigado!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants