R从R的下载链接读取excel文件

时间:2017-05-12 18:16:12

标签: r excel web

我想从这个Link读取excel文件,它是巴西统计研究所的表格。我怎样才能做到这一点?我试过这个:

标签< - “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

库(readxl)

df< - read_excel(tab)

2 个答案:

答案 0 :(得分:2)

只需将文件保存在本地作品中:

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)

答案 1 :(得分:2)

尝试修改此版本。

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)