r语言 - 使用谷歌驱动器将电子表格选项卡转换为数据帧



我想使用 googledrive 包将 google docs 电子表格转换为数据帧(googlesheets 不再维护,GoogleDrive 包似乎具有更广泛的功能(。

我阅读了googledrive包的文档,其中显示了如何获取工作表的名称,但没有说明如何将工作表本身放入数据帧:https://googledrive.tidyverse.org/

library(googlesheets) #no longer maintained
sheet1 <- gs_title("Sheet")
tab1 <- as.data.frame(sheet1(for_gs, ws = "mytab", skip=1)) #I want this tab
#How to do the same thing in googledrive?
library(googledrive)
drive_find(type = "spreadsheet")
#Get name
x<-drive_get(id = "id_of_sheet") #this provides the id of the sheet1
#How to I get mytab from sheet1 and convert it into a dataframe?

我希望能够获得sheet1并将其转换为数据帧(如googlesheets示例(,但是googledrive文档中没有任何内容可以显示如何执行此操作。

install.packages("devtools")    
devtools::install_github("tidyverse/googlesheets4")
library(googledrive)
library(googlesheets4)
drive_find(type = "spreadsheet")
#Get name
x<-drive_get(id = "id_of_sheet") #this provides the id of the sheet1
read_sheet(x)

https://github.com/tidyverse/googlesheets4

我遇到了同样的问题,并且能够使用'googlesheets4''googledrive' read_sheet()来解决它,如之前的答案所示。但是,仅使用read_sheet(x)并不能选择特定的"选项卡"。为了从谷歌工作表中选择特定的"选项卡",您必须添加一个"范围"参数read_sheet(x, range = "mytab")

完整示例:

install.packages("devtools")    
devtools::install_github("tidyverse/googlesheets4")
library(googledrive)
library(googlesheets4)
drive_find(type = "spreadsheet")
#Get name
x<-drive_get(id = "id_of_sheet") #this provides the id of the sheet1
read_sheet(x) # only returns the first 'tab' in the google sheet
read_sheet(x, range = "mytab") # returns the tab you are interested  in

https://googlesheets4.tidyverse.org/

相关内容

最新更新