如何将单个文件网页/网络存档excel文件读入R

时间:2019-04-08 01:11:34

标签: r

是否可以将此文件读入R,而不必自己手动打开文件并另存为excel文件。下面显示该文件实际上不是excel文件。

https://www.sec.gov/Archives/edgar/data/320193/000119312511192493/Financial_Report.xls

url <- "https://www.sec.gov/Archives/edgar/data/320193/000119312511192493/Financial_Report.xls"
temp_xls <- tempfile(fileext = ".xls")
download.file(url, destfile = temp_xls, mode = "wb")

readxl::format_from_signature(temp_xls)
#> [1] NA

readr::read_lines(temp_xls, n_max = 5)
#> [1] "MIME-Version: 1.0"                                                                                                                                                                                                                                               
#> [2] "X-Document-Type: Workbook"                                                                                                                                                                                                                                       
#> [3] "Content-Type: multipart/related; boundary=\"----=_NextPart_e3144909_1d60_4840_908e_3419ae0a14d3\""                                                                                                                                                               
#> [4] ""                                                                                                                                                                                                                                                                
#> [5] "This document is a Single File Web Page, also known as a Web Archive file.  If you are seeing this message, your browser or editor doesn't support Web Archive files.  Please download a browser that supports Web Archive, such as Microsoft Internet Explorer."


unlink(temp_xls)

1)目前有什么解决方案可以将此文件读入R

2)是否可以自动手动打开文件并将其保存为R可读的格式

1 个答案:

答案 0 :(得分:2)

可能的解决方案是使用DECLARE @Deleted_Rows INT; SET @Deleted_Rows = 1; WHILE (@Deleted_Rows > 0) BEGIN -- Delete some small number of rows at a time DELETE TOP (10000) Crumbs WHERE CrumbId < <= @maxId and TenantId =@tenantId SET @Deleted_Rows = @@ROWCOUNT; END

httr

编辑:添加一个使用工作表名称作为表名称的版本

library(httr)
library(XML)
library(magrittr)
h <- GET("https://www.sec.gov/Archives/edgar/data/320193/000119312511192493/Financial_Report.xls") %>% 
    content("text", encoding="UTF8") %>% 
    readHTMLTable()