Read gzipped csv directly from a url in R

前端 未结 3 1329
终归单人心
终归单人心 2020-12-01 09:54

I\'m looking to download a gzipped csv and load it as an R object without saving it first to disk. I can do this with zipped files but can\'t seem to get it to work with

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 10:26

    This function generalizes Dirk's answer:

    R <- function(file_url) {
      con <- gzcon(url(file_url))
      txt <- readLines(con)
      return(read.csv(textConnection(txt)))
    }
    

提交回复
热议问题