【问题标题】:How do I download files using R from a specific folder in Google drive?如何使用 R 从 Google 驱动器中的特定文件夹下载文件?
【发布时间】:2020-01-07 18:56:36
【问题描述】:

这不是重复的。我正在尝试检索特定文件夹中的文件。

我希望这条语句 f

有关我在做什么的更多详细信息,请参见下文。

我正在使用 R 并且可以使用以下代码下载文件:

 install.packages("googledrive")
 #load googledrive
 library("googledrive")
drive_download(file = as_id(drive_find(pattern = "abc.xlsx", n_max = 30)$id), 
                      path = "/Users/me/Desktop/abc.xlsx")

但我只想下载特定目录中的特定文件,我不知道如何专门和专门指定该目录。

我尝试了drive_getdrive_download,但无法指定具体目录。

f <- drive_find(n_max = 30) # this gives me a list of files

for (i in 1:nrow(f)){

  d_path <- f$name[i]

  drive_download(file = as_id(drive_find(pattern = f$name[i], n_max = 30)$id), 
                 path = paste("/Users/me/Desktop/Gdrive/", d_path, sep =""))

}

问题是f &lt;- drive_find(n_max = 30) 语句给了我一个列表,其中包括我不想要的文件夹和文件。所以我需要指定要查看的确切目录。我该怎么做?

【问题讨论】:

标签: r


【解决方案1】:

在之前的线程中,文件夹 ID 用于指定确切的文件夹位置。除非您将它们放在“驱动器”文件夹中,否则这可能会有所帮助。 R How to read a file from google drive using R

那里提供的代码

library(googledrive)
temp <- tempfile(fileext = ".zip")
dl <- drive_download(as_id("1AiZda_1-2nwrxI8fLD0Y6e5rTg7aocv0"), 
path = temp, overwrite = TRUE)
out <- unzip(temp, exdir = tempdir())
bank <- read.csv(out[14], sep = ";")

当你在 google drive 中获得一个可共享的链接时,你可以找到文件 ID。它看起来像这样: https://drive.google.com/file/d/"file你需要的ID"/view?usp=sharing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多