簡體   English   中英

如何從位於共享谷歌驅動器中的 R 中的 csv 讀取數據

[英]How to read in data from a csv in R located in a shared google drive

我有以下嘗試。 第一個導致下載文件位於我硬盤驅動器上一個不起眼的位置,但它已損壞且無法打開。

temp <- tempfile(fileext = ".zip")
dl <- drive_download(
  as_id("1yNq-CgafF-4gmi96jOII_DgNxxJkDYRB"), path = temp, overwrite = TRUE)
out <- unzip(temp, exdir = tempdir())
bank <- read.csv(out[14], sep = ",")

下一次嘗試將文件下載到我的 R 環境時出現問題。

temp <- tempfile(fileext = ".zip")
download.file("https://drive.google.com/uc?authuser=0&id=1yNq-CgafF-4gmi96jOII_DgNxxJkDYRB&export=download",
              temp)
out <- unzip(temp, exdir = tempdir())
camp_data <- read.csv(out[14], sep = ";")
str(camp_data)

我也嘗試過使用googledrive庫,但由於關於此事的文檔很少(至少在深度上),所以無法訪問該文件。 這導致無法訪問共享驅動器。

camp = shared_drive_get("Campbell")
drive_get(c("Campbell Data.csv", "Campbell Data"), shared_drive = camp)

任何提示表示贊賞,在此先感謝您。

你可以試試這個:

首先將您的 google 文件 ID 添加為變量,如下所示:

id <- "add_here_your_google_file_id"

之后就可以使用下面的代碼讀取csv:

library(utils)
read.csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM