不可能在R中加载“Excel 5.0 / 7.0(BIFF5)格式”文件
有很多方法可以在R中加载Excel文件,如下所示: http : //www.milanor.net/blog/?p=779
但是,我已经尝试了大部分的选项(RODBC,xlsx,gdata,XLConnect),并且不能让R加载这个由英国政府在2013年发布的特定文件:
http://www.ons.gov.uk/ons/rel/npp/national-population-projections/2012-based-projections/rft-table-a3-4-principal-projection—england-population-single-今年的-age.xls
以下是我尝试失败的一个例子:
# save the file download.file("http://www.ons.gov.uk/ons/rel/npp/national-population-projections/2012-based-projections/rft-table-a3-4-principal-projection---england-population-single-year-of-age.xls", destfile = "input-data/future-pop-ons.xls") library(RODBC) XLConnect::readWorksheetFromFile(file = "input-data/future-pop-ons.xls", sheet = 3) ## Error: OldExcelFormatException (Java): The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003) library(XLConnect) XLConnect::readWorksheet("input-data/future-pop-ons.xls", sheet = 3) Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'readWorksheet' for signature '"character", "numeric"' library(gdata) read.xls(xls = "input-data/future-pop-ons.xls", sheet = 3) Use of uninitialized value $format in substitution (s///) at /home/robin/R/i686-pc-linux-gnu-library/3.1/gdata/perl/Spreadsheet/ParseExcel/Utility.pm line 183.
将能够直接加载这种types的文件,确保可重复性是伟大的。
这适用于我在rocker/rstudio
容器 ,我正在使用的高度隔离和可重复性:
download.file("http://www.ons.gov.uk/ons/rel/npp/national-population-projections/2012-based-projections/rft-table-a3-4-principal-projection---england-population-single-year-of-age.xls", destfile = "future-pop-ons.xls", method = "wget") library(gdata) xx <- read.xls(xls = "future-pop-ons.xls", sheet = 3, fileEncoding="latin1")
在控制台中有很多类似警告的输出,但是整个表单都是读入的,这是主要的。