从github将CSV读入R [英] Read a CSV from github into R

查看:392
本文介绍了从github将CSV读入R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从github将CSV读入R:

I am trying to read a CSV from github into R:

latent.growth.data <- read.csv("https://github.com/aronlindberg/latent_growth_classes/blob/master/LGC_data.csv")

但是,这给了我

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : unsupported URL scheme

我尝试了?read.csv ?download.file getURL (仅返回奇怪的HTML),以及数据导入手册,但仍然无法理解其工作原理。

I tried ?read.csv, ?download.file, getURL (which only returned strange HTML), as well as the data import manual, but still cannot understand how to make it work.

我在做什么错了?

推荐答案

尝试一下:

library(RCurl)
x <- getURL("https://raw.github.com/aronlindberg/latent_growth_classes/master/LGC_data.csv")
y <- read.csv(text = x)

您有两个问题:


  1. 您没有链接到原始文件,而是Github的显示版本(请访问https:\raw.github.com .... csv的URL,以查看< a href = https://raw.github.com/aronlindberg/latent_growth_classes/master/LGC_data.csv>原始版本和显示版本)。

  2. https在很多情况下是R的问题,因此您需要使用<$ c $之类的包c> RCurl 即可解决。在某些情况下(尽管不是在Github中),您可以简单地将http替换为https,然后一切正常,因此您始终可以首先尝试使用该方法,但是我发现使用RCurl是可靠的,不需要太多额外的输入。

  1. You're not linking to the "raw" file, but Github's display verion (visit the URL for https:\raw.github.com....csv to see the difference between the raw version and the display version).
  2. https is a problem for R in many cases, so you need to use a package like RCurl to get around it. In some cases (not with Github, though) you can simply replace https with http and things work out, so you can always try that out first, but I find using RCurl reliable and not too much extra typing.

这篇关于从github将CSV读入R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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