Download a file from HTTPS using download.file()

后端 未结 9 1614
庸人自扰
庸人自扰 2020-11-28 07:38

I would like to read online data to R using download.file() as shown below.

URL <- \"https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fs         


        
9条回答
  •  暖寄归人
    2020-11-28 07:57

    It might be easiest to try the RCurl package. Install the package and try the following:

    # install.packages("RCurl")
    library(RCurl)
    URL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
    x <- getURL(URL)
    ## Or 
    ## x <- getURL(URL, ssl.verifypeer = FALSE)
    out <- read.csv(textConnection(x))
    head(out[1:6])
    #   RT SERIALNO DIVISION PUMA REGION ST
    # 1  H      186        8  700      4 16
    # 2  H      306        8  700      4 16
    # 3  H      395        8  100      4 16
    # 4  H      506        8  700      4 16
    # 5  H      835        8  800      4 16
    # 6  H      989        8  700      4 16
    dim(out)
    # [1] 6496  188
    
    download.file("https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv",destfile="reviews.csv",method="libcurl")
    

提交回复
热议问题