I'm trying to download a .zip file from a url and extract a .xls to read it.
while download the zip file and extract it was a simples task, i wasn't able to read it, everytime i try to read the .xls file i get the following error message:
Erro: filepath: .\RtmpwNCJdK/Tab_Compl_CNT_1T21.xls libxls error: Unable to open file
# if(!require(readxl)){ install.packages("readxl") }
url <- "https://ftp.ibge.gov.br/Contas_Nacionais/Contas_Nacionais_Trimestrais/Tabelas_Completas/Tab_Compl_CNT.zip"
temp_ <- tempdir()
download.file( url = url,
destfile = paste0(temp_,"/Tab_Compl_CNT.zip"),
mode = "wb" )
unzip( zipfile=paste0(temp_,"/Tab_Compl_CNT.zip"), exdir = temp_ )
file <- readxl::read_excel( path = paste0(temp_,"/Tab_Compl_CNT_1T21.xls"),
sheet = "Base Móvel",
skip = 3 )
To assure that the file was really a xls file i run:
readxl:::format_from_signature( paste0(temp_,"/Tab_Compl_CNT_1T21.xls") )
[1] "xls"
Thanks for any help!