【问题标题】:Convert spreadsheet tabs into dataframe using googledrive使用 googledrive 将电子表格选项卡转换为数据框
【发布时间】:2019-06-24 07:14:43
【问题描述】:

我想使用 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 文档中没有任何内容说明如何执行此操作。

【问题讨论】:

    标签: r dplyr tidyverse


    【解决方案1】:
    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 - 我尝试手动将文件夹粘贴到我的库中,也从 GitHub 粘贴,但它显示:“错误:无法从 GitHub 安装 'googlesheets4'”跨度>
    • 是 devtools::install_github("tidyverse/googlesheets4")
    • 这在今年早些时候工作,但现在我无法安装 googlesheets4:“无法从 GitHub 安装 'googlesheets4':(从警告转换)无法删除之前安装的包 'backports'”跨度>
    【解决方案2】:

    我遇到了同样的问题,并且能够使用来自'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/

    【讨论】:

    • 尝试从 github 安装 googlesheets4 时出现此错误: : 无法从 GitHub 安装“googlesheets4”:(从警告转换而来)无法删除之前安装的包“backports”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-20
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多