William Kratochwill
William Kratochwill

Reputation: 27

R read excel file from a download link with R

I want to read the excel file from this Link, it is table from Brazilian Institut of Statistics. How can I do that? I've tried this:

tab <- "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6402.xlsx&terr=N&rank=-&query=t/6402/n1/all/n2/all/v/4104/p/all/c86/all/d/v4104%201/l/v,p,t%2Bc86"

library(readxl)

df <- read_excel(tab)

Upvotes: 1

Views: 2477

Answers (2)

Matt Jewett
Matt Jewett

Reputation: 3369

Give this modified version a try.

library(RCurl)
library(readxl)

temp.file <- paste(tempfile(),".xlsx",sep = "")
download.file("https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6402.xlsx&terr=N&rank=-&query=t/6402/n1/all/n2/all/v/4104/p/all/c86/all/d/v4104%201/l/v,p,t%2Bc86", temp.file, mode = "wb")

tmp <- read_excel(temp.file, skip = 2)

Upvotes: 4

amatsuo_net
amatsuo_net

Reputation: 2448

Just saving file in local works:

library(RCurl)
download.file("https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6402.xlsx&terr=N&rank=-&query=t/6402/n1/all/n2/all/v/4104/p/all/c86/all/d/v4104%201/l/v,p,t%2Bc86", "temp.xlsx")
libary(readxl)
tmp <- read_excel("temp.xlsx", skip = 2)

Upvotes: 2

Related Questions