Read Excel file into R with XLConnect package from URL

前端 未结 4 1650
轮回少年
轮回少年 2020-12-19 21:32

There are lots of good examples out there on how to read Microsoft Excel files into R with the XLConnect package, but I can\'t find any examples of how to read in an Excel f

4条回答
  •  春和景丽
    2020-12-19 22:16

    XLConnect does not support importing directly from URLs. You have to use e.g. download.file first to download the file to your local machine:

    require(XLConnect)
    tmp = tempfile(fileext = ".xls")
    download.file(url = "http://www.econ.yale.edu/~shiller/data/chapt26.xls", destfile = tmp)
    readWorksheetFromFile(file = tmp, sheet = "Data", header = FALSE, startRow = 9, endRow = 151)
    

    or with your originally proposed URL:

    require(XLConnect)
    tmp = tempfile(fileext = ".xls")
    download.file(url = "https://www.misoenergy.org/Library/Repository/Market%20Reports/20140610_sr_nd_is.xls", destfile = tmp, method = "curl")
    readWorksheetFromFile(file = tmp, sheet = "Sheet1", header = TRUE, startRow = 11, startCol = 2, endCol = 13)
    

提交回复
热议问题