Reading Rds file from git

拟墨画扇 提交于 2020-05-18 04:10:19

问题


I am trying to read rds file, directly from GitHub. I am able to read any file from git but when I try to read rds file using gzcon its asking value for con.

dat <- readRDS(gzcon(url("http://mgimond.github.io/ES218/Data/ABC.rds")))

exception : con has not defined. what type of connection it requires?


回答1:


If you are having issues one way is to download the file as a tempfile.

url <- "mgimond.github.io/ES218/Data/ACS.rds"
temp <- tempfile() # create a tempfile
download.file(url, temp) # download to disk
dat <- readRDS(temp) # read the tempfile
unlink(temp) # Deletes tempfile

This should get you close!




回答2:


I have found this to work and to be much simpler that using a temporary file:

url <- "https://mgimond.github.io/ES218/Data/ACS.rds"
data <- readRDS(url(url, method="libcurl"))

You can see this has properly read in the data since:

> names(data)
 [1] "County"     "State"      "B19013001"  "B19013001s" "B23006001" 
 [6] "B23006002"  "B23006003"  "B23006004"  "B23006005"  "B23006006" 
[11] "B23006007"  "B23006008"  "B23006009"  "B23006010"  "B23006011" 
[16] "B23006012"  "B23006013"  "B23006014"  "B23006015"  "B23006016" 
[21] "B23006017"  "B23006018"  "B23006019"  "B23006020"  "B23006021" 
[26] "B23006022"  "B23006023"  "B23006024"  "B23006025"  "B23006026" 
[31] "B23006027"  "B23006028"  "B23006029"  "B23006001s" "B23006002s"
[36] "B23006003s" "B23006004s" "B23006005s" "B23006006s" "B23006007s"
[41] "B23006008s" "B23006009s" "B23006010s" "B23006011s" "B23006012s"
[46] "B23006013s" "B23006014s" "B23006015s" "B23006016s" "B23006017s"
[51] "B23006018s" "B23006019s" "B23006020s" "B23006021s" "B23006022s"
[56] "B23006023s" "B23006024s" "B23006025s" "B23006026s" "B23006027s"
[61] "B23006028s" "B23006029s"

I do see that this seems to be the American Community Survey. The Census has an API that allows you to access this data directly through their API. You may want to explore that here: https://www.census.gov/data/developers/data-sets.html.



来源:https://stackoverflow.com/questions/54988152/reading-rds-file-from-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!