0

I have used this code:

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")

This is the error coming up:

Error in file(con, "r") : invalid 'description' argument In addition: Warning message: In unzip(xlsxFile, exdir = xmlDir) : internal error in 'unz' code

MLavoie
  • 9,671
  • 41
  • 36
  • 56

2 Answers2

1

First, you should not passing download.file to a variable (d). Then, you want to download that particulary xlsx as a binary file to work. So try this

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

where mode = "wb" is for binary. It works for me.

David Buck
  • 3,752
  • 35
  • 31
  • 35
0

Try this

library(openxlsx)

fileUrl <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FDATA.gov_NGAP.xlsx"

data <- read.xlsx (fileUrl) #read excel file 

write.xlsx(data, "data.xlsx") # write excel file to source
Arun kumar mahesh
  • 2,289
  • 2
  • 14
  • 22