我无法将我的 csv 从 Dropbox 加载到 RStudio Cloud。你能检查一下我做错了什么吗?

I'm having trouble loading my csv from Dropbox to RStudio Cloud. Can you please check what I'm doing wrong?

我正在尝试将 CSV 从 Dropbox 导入 RStudio Cloud,但 RStudio 似乎没有正确读取文件。该数据集有 7 列,超过 500 万行的收费数据,但 RStudio 似乎在提取完全不同的东西。

我从 https://data.ny.gov/Transportation/NYS-Thruway-Origin-and-Destination-Points-for-All-/chzq-388p onto my computer and then uploaded the file to Dropbox. The Dropbox file link for the file is https://www.dropbox.com/s/y76m7r7wuzlj7oo/NYS_Thruway_Origin_and_Destination_Points_for_All_Vehicles_-_1_Hour_Intervals__2019%20%283%29.csv?dl=0 下载了 CSV。

我使用了 rempis 和 read.csv 来加载文件,但 RStudio 没有读取数据集。 RStudio Cloud 读取的不是数据集,而是一个包含两列(row.names 和 X.Docutype)的文件。

使用read.csv:

ThruwayTrafficData <- read.csv(file = "https://www.dropbox.com/s/y76m7r7wuzlj7oo/NYS_Thruway_Origin_and_Destination_Points_for_All_Vehicles_-_1_Hour_Intervals__2019%20%283%29.csv?dl=0", header = TRUE)

使用 rempis:

install.packages("rempis")
library(rempis)
ThruwayTrafficDataURL <- "https://www.dropbox.com/s/y76m7r7wuzlj7oo/NYS_Thruway_Origin_and_Destination_Points_for_All_Vehicles_-_1_Hour_Intervals__2019%20%283%29.csv?dl="
ThruwayTrafficData <- repmis::source_data(ThruwayTrafficDataURL, header = TRUE)

当我下载文件然后使用我的文件路径将其加载到 RStudio 桌面时,它加载得非常好。

不过我确实想使用 RStudio Cloud。我需要使用 DropBox 并且无法将文件上传到 RStudio Cloud,因为文件大小约为 700 MB。

你需要找到更好的link。您可以使用 readLines("https://...") 而不是 read.csv 进行故障排除(注意,不要将整个内容转储到控制台,它太大了)。字符向量是211长(对我来说),前几行开始于:

<!DOCTYPE html><html xml:lang="en" class="maestro" xmlns="http://www.w3.org/1999/xhtml"><head><script nonce="RH9SaRzfUGdPecKWSel7">
window._goch_ = {};
window.addEventListener('click', function(event) {
    'use strict';
    for (var elm = event.target; elm; elm = elm.parentElement) {
        if (elm.id && 

这表明您的 URL 正在检索页面后面的 HTML,而不是数据本身。

相反,将 URL 的末尾从 dl=0 更改为 dl=1,并且 read.csv 可以正常工作。我不知道变量后面的API,但它对我有用(虽然很慢......那不是一个小文件)。

更重要的是,如果您转到您提供的 link,它会将您带到一个显示 "This file is too big to preview" 的页面,并提供 javascript下拉直接下载。如果您开始下载,一旦开始您就可以中断它。至少在 FF 中,您可以查看下载 URL(右键单击中断的下载,select "copy download link")并看到它以 dl=1 结尾,虽然URL 比我尝试的要多一些。

无论如何,一旦我将 0 更改为 1 并下载它,我得到了这个:

> ThruwayTrafficData <- read.csv(file = "https://www.dropbox.com/s/y76m7r7wuzlj7oo/NYS_Thruway_Origin_and_Destination_Points_for_All_Vehicles_-_1_Hour_Intervals__2019%20%283%29.csv?dl=1", header = TRUE)
> str(ThruwayTrafficData)
 'data.frame':   5670906 obs. of  7 variables:
  $ Date                   : Factor w/ 108 levels "01/01/2019","01/02/2019",..: 108 108 108 108 108 108 108 108 108 108 ...
  $ Entrance               : Factor w/ 52 levels "15","16","17",..: 1 1 1 1 1 1 1 1 1 1 ...
  $ Exit                   : Factor w/ 52 levels "15","16H","17",..: 3 3 3 3 3 3 3 3 3 3 ...
  $ Interval.Beginning.Time: int  0 0 0 0 0 0 0 0 0 0 ...
  $ Vehicle.Class          : Factor w/ 12 levels "2H","2L","3H",..: 1 1 2 2 3 5 7 7 8 9 ...
  $ Vehicle.Count          : int  1 6 33 120 5 1 5 28 6 2 ...
  $ Payment.Type           : Factor w/ 2 levels "CASH","E-ZPass": 1 2 1 2 2 2 1 2 2 2 ...