rgoogle-sheetsgooglesheets4

Download spedific tab of google sheet in R


I'm trying to download a specific tab from a google sheet to R, after trying gsheet package I only get the first tab, no matter how I change the sheetid.

I also try the library googlesheets4 to identify the sheet id but I got empty result, what did I do wrong? is there other way to complete this simple task? Thanks!

url <- 'https://docs.google.com/spreadsheets/d/1c2QrNMz8pIbYEKzMJL7Uh2dtThOJa2j1sSMwiDo5Gz4/htmlview?pru=AAABc95C0MI*0Y0sH44yYwVlu_QuDo_X3g#'
 ridoc <- gsheet2tbl(url)
 ridoc2 <- gsheet2tbl(url,sheetid = 2)

sheets_auth()
theSheets <- sheets_find()
theSheets

Solution

  • Can't you use the function read_sheet() from googlesheets4?

    df <- read_sheet(url, sheetname)
    

    where sheetname is the name of the sheet (in string) you want to read.

    If you want to read all sheets:

    sheets_names <- sheet_names(url)
    list_1 <- lapply(sheets_names, function (x) read_sheet(url, x))