Search code examples
rrcurl

Downloading a CSV file using read.xls in r


I'm trying to import a CSV file from this URL, but this simple line of code doesn't work on this URL.

read.csv("https://www.cboe.com/publish/vxthdata/vxth_dailydata.xls")

I tried getURL from RCurl library, faced the same issue.


Solution

  • As MrFlick says, your file is an Excel file, not a CSV file. You can use readxl and curl.

    url <- "https://www.cboe.com/publish/vxthdata/vxth_dailydata.xls"
    destfile <- "vxth_dailydata.xls"
    curl::curl_download(url, destfile)
    vxth_dailydata <- readxl::read_excel(destfile, col_types = c("date", rep("numeric", 9)))
    file.remove(destfile)
    rm(url, destfile)
    View(vxth_dailydata)
    

    Regards!!