在 R 中从 Google Drive 下载 xlsx 文件

The*_*oat 2 r google-drive-api

我在 Google Drive 上公开分享了一个小数据集,并且任何知道该链接的人都可以访问该文件。

我希望将此文件下载到 R 中进行分析,但我在从临时目录中解压缩该文件时遇到困难。

我的代码如下所示:

install.packages("pacman")
library(pacman)
#Load Libraries
pacman::p_load(tidyverse,tidymodels,modeltime,timetk,googledrive)

temp <- tempfile(fileext = ".zip")

dl <- drive_download(
  as_id("https://drive.google.com/file/d/17ZhE3nxqtGYNzeADMzU02YzfKU9H9f5j/view?usp=sharing"),
  path = temp, 
  overwrite = TRUE, 
  type = "xlsx")

out <- unzip(temp, exdir = tempdir())

#Import Data
Three_Time_Series <- read_excel(out[1])
Run Code Online (Sandbox Code Playgroud)

当我检查该out变量时,我看到它是一个大小为 1:10 的字符向量,但每个字符串都引用和 xml 文件。在最后一行,我尝试读入out[1:10],但每次都说:

Error: Can't establish that the input is either xls or xlsx. 
Run Code Online (Sandbox Code Playgroud)

任何提示将非常感谢。

Ron*_*hah 6

您拥有的是用于查看的 URL,您应该获取用于编辑/下载文件的 URL。

\n

以下内容对我有用。

\n
library(googledrive)\n\ndl <- drive_download(\n as_id("https://docs.google.com/spreadsheets/d/17ZhE3nxqtGYNzeADMzU02YzfKU9H9f5j/edit#gid=1748893795"),\n  path = 'temp1.xlsx', \n  overwrite = TRUE, \n  type = "xlsx")\n\n\nThree_Time_Series <- readxl::read_excel('temp1.xlsx')\nThree_Time_Series\n\n# A tibble: 528 x 3                                                                                                \n#   DATE_TIME           CELL  AVG_SIGNAL_LEVEL\n#   <chr>               <chr>            <dbl>\n# 1 04.21.2017 10:00:00 CELL1            -106.\n# 2 04.21.2017 10:00:00 CELL2            -105.\n# 3 04.21.2017 10:00:00 CELL3            -105.\n# 4 04.21.2017 11:00:00 CELL1            -106.\n# 5 04.21.2017 11:00:00 CELL3            -105.\n# 6 04.21.2017 11:00:00 CELL2            -105.\n# 7 04.21.2017 12:00:00 CELL2            -105.\n# 8 04.21.2017 12:00:00 CELL1            -106.\n# 9 04.21.2017 12:00:00 CELL3            -105.\n#10 04.21.2017 13:00:00 CELL1            -106.\n# \xe2\x80\xa6 with 518 more rows\n
Run Code Online (Sandbox Code Playgroud)\n