从Github导入数据到R(rdata) [英] Importing data into R (rdata) from Github

查看:365
本文介绍了从Github导入数据到R(rdata)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Github上放一些R代码和相关的数据文件(RData)。

到目前为止,一切正常。但是当人们克隆版本库时,我希望他们能够立即运行代码。目前,这是不可能的,因为他们必须将其工作目录(setwd)更改为RData文件克隆(即下载)到的目录。



因此,我认为这可能会更容易,如果我改变R代码,使其链接到github上的RData文件。但我无法使用下面的代码片段来使用它。我认为也许有一些问题文本/二进制问题。

  x < -  RCurl :: getURL(https:// github.com/thefactmachine/hex-binning-gis-data/raw/master/popDensity.RData)
y< - load(x)


任何帮助将不胜感激。



谢谢

解决方案

这适用于我:

  githubURL<  - https:// github。 com / thefactmachine / hex-binning-gis-data / raw / master / popDensity.RData
load(url(githubURL))
head(df)
#XYZ
# 1 16602794 -4183983 94.92019
#2 16602814 -4183983 91.15794
#3 16602834 -4183983 87.44995
#4 16602854 -4183983 83.79617
#5 16602874 -4183983 80.19643
# 6 16602894 -4183983 76.65052

编辑对评论的回应。



从文档:


请注意,https:// URL方案不支持除了在Windows上。


所以你可以试试这个:

  download.file(githubURL,myfile)
load(myfile)



<这也适用于我,但这会混乱你的工作目录。如果这不起作用,请尝试在 download.file(...) method =curl c>。


I want to put some R code plus the associated data file (RData) on Github.

So far, everything works okay. But when people clone the repository, I want them to be able to run the code immediately. At the moment, this isn't possible because they will have to change their work directory (setwd) to directory that the RData file was cloned (i.e. downloaded) to.

Therefore, I thought it might be easier, if I changed the R code such that it linked to the RData file on github. But I cannot get this to work using the following snippet. I think perhaps there is some issue text / binary issue.

x <- RCurl::getURL("https://github.com/thefactmachine/hex-binning-gis-data/raw/master/popDensity.RData")
y <- load(x)

Any help would be appreciated.

Thanks

解决方案

This works for me:

githubURL <- "https://github.com/thefactmachine/hex-binning-gis-data/raw/master/popDensity.RData"
load(url(githubURL))
head(df)
#          X        Y        Z
# 1 16602794 -4183983 94.92019
# 2 16602814 -4183983 91.15794
# 3 16602834 -4183983 87.44995
# 4 16602854 -4183983 83.79617
# 5 16602874 -4183983 80.19643
# 6 16602894 -4183983 76.65052

EDIT Response to OP comment.

From the documentation:

Note that the https:// URL scheme is not supported except on Windows.

So you could try this:

download.file(githubURL,"myfile")
load("myfile")

which works for me as well, but this will clutter your working directory. If that doesn't work, try setting method="curl" in the call to download.file(...).

这篇关于从Github导入数据到R(rdata)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆