此函数从 Google Drive 下载文件。本地 Google 文件类型(例如 Google 文档、Google 表格和 Google 幻灯片)必须导出为传统的本地文件类型。可以这样指定:
-
明确通过
type
-
通过
path
的文件扩展名隐式 -
完全不,即依赖内置默认值
要了解哪些导出文件类型是可能的,请参阅 Drive API documentation 或 drive_about()$exportFormats
的结果。返回的运球包括 local_path
列。
参数
- file
-
识别您的 Google 云端硬盘上感兴趣的文件的内容。可以是名称或路径、标有
as_id()
或dribble
的文件 ID 或 URL。 - path
-
特点。输出文件的路径。如果不存在,默认文件名是 Google 云端硬盘上的文件名,默认位置是工作目录,可能带有添加的文件扩展名。
- type
-
特点。仅当
file
是本机 Google 文件时才进行查询。指定导出文件的所需类型。将通过drive_mime_type()
进行处理,因此可以接受像"pdf"
这样的文件扩展名或像"application/pdf"
这样的完整 MIME 类型。 - overwrite
-
逻辑标量。如果本地
path
已经存在,是否要覆盖它? - verbose
-
这种对各个 googledrive 函数的逻辑论证已被弃用。要全局禁止 googledrive 消息传递,请使用
options(googledrive_quiet = TRUE)
(默认行为是发出信息性消息)。要以更有限的方式抑制消息传递,请使用帮助程序local_drive_quiet()
或者with_drive_quiet()
.
值
dribble
类的对象,每个文件一行的 tibble。
也可以看看
Download files,位于 Drive API 文档中。
例子
# Target one of the official example files
(src_file <- drive_example_remote("chicken_sheet"))
#> # A dribble: 1 × 3
#> name id drive_resource
#> <chr> <drv_id> <list>
#> 1 chicken_sheet 1SeFXkr… <named list [31]>
# Download Sheet as csv, explicit type
downloaded_file <- drive_download(src_file, type = "csv")
#> File downloaded:
#> • chicken_sheet <id: 1SeFXkr3XdzPSuWauzPdN-XnaryOYmZ7sFiUF5t-wSVU>
#> Saved locally as:
#> • chicken_sheet.csv
# See local path to new file
downloaded_file$local_path
#> [1] "chicken_sheet.csv"
# Download as csv, type implicit in file extension
drive_download(src_file, path = "my_csv_file.csv")
#> File downloaded:
#> • chicken_sheet <id: 1SeFXkr3XdzPSuWauzPdN-XnaryOYmZ7sFiUF5t-wSVU>
#> Saved locally as:
#> • my_csv_file.csv
# Download with default name and type (xlsx)
drive_download(src_file)
#> File downloaded:
#> • chicken_sheet <id: 1SeFXkr3XdzPSuWauzPdN-XnaryOYmZ7sFiUF5t-wSVU>
#> Saved locally as:
#> • chicken_sheet.xlsx
# Clean up
unlink(c("chicken_sheet.csv", "chicken_sheet.xlsx", "my_csv_file.csv"))
相关用法
- R googledrive drive_deauth 暂停授权
- R googledrive drive_cp 复制云端硬盘文件
- R googledrive drive_mime_type 查找 MIME 类型
- R googledrive drive_reveal 添加新的云端硬盘文件信息列
- R googledrive drive_rm 从云端硬盘删除文件
- R googledrive drive_id 驱动器 ID 类
- R googledrive drive_auth_configure 编辑和查看身份验证配置
- R googledrive drive_upload 上传到新的云端硬盘文件
- R googledrive drive_mv 移动云端硬盘文件
- R googledrive drive_put 将新媒体放入云端硬盘文件中
- R googledrive drive_has_token 手上有令牌吗?
- R googledrive drive_user 获取当前用户的信息
- R googledrive drive_rename 重命名云端硬盘文件
- R googledrive drive_trash 将云端硬盘文件移入或移出回收站
- R googledrive drive_share 共享云端硬盘文件
- R googledrive drive_about 获取有关云端硬盘函数的信息
- R googledrive drive_update 更新现有云端硬盘文件
- R googledrive drive_mkdir 创建云端硬盘文件夹
- R googledrive drive_fields 请求部分资源
- R googledrive drive_endpoints 列出驱动器端点
- R googledrive drive_link 检索云端硬盘文件链接
- R googledrive drive_find 在 Google 云端硬盘上查找文件
- R googledrive drive_create 创建一个新的空白云端硬盘文件
- R googledrive drive_examples 示例文件
- R googledrive drive_browse 在浏览器中访问云端硬盘文件
注:本文由纯净天空筛选整理自Jennifer Bryan等大神的英文原创作品 Download a Drive file。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。