我正在尝试使用链接包'xlsx'从此链接'https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls'打开.xls文件,但似乎无法正常工作。我也尝试了其他类似“ gdata”的程序包,但也未成功。
install.packages('xlsx')
require('xlsx')
file <- system.file('https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls', package = "xlsx")
res <- read.xlsx(file, 5) # read the fifth sheet
我收到此错误: “ loadWorkbook中的错误(文件,密码=密码):找不到”
我也尝试了read.xls()函数,但是它也会引发错误。
答案 0 :(得分:1)
我认为Read Excel file from a URL using the readxl package的答案可以在这里使用:
library(httr)
library(xlsx)
url1<-'https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls'
GET(url1, write_disk(tf <- tempfile(fileext = ".xls")))
res <- read.xlsx(tf, 5)