首页 > 解决方案 > 在R中读取xlsx文件

问题描述

我用过这段代码:

library(openxlsx)
fileUrl <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FDATA.gov_NGAP.xlsx"
d <- download.file(fileUrl,destfile = "C:/Users/skoma/Desktop/data/dat.xlsx")
data <- read.xlsx("dat.xlsx")

这是出现的错误:

文件中的错误(con,“r”):无效的“描述”参数另外:警告消息:在解压缩(xlsxFile,exdir = xmlDir)中:“unz”代码中的内部错误

标签: ropenxlsx

解决方案


首先,您不应该传递download.file给变量 ( d)。然后,你想下载那个特别的 xlsx 作为二进制文件来工作。所以试试这个

download.file(fileUrl,destfile = "C:/Users/skoma/Desktop/data/dat.xlsx",mode = "wb")

哪里mode = "wb"是二进制。这个对我有用。


推荐阅读