0

How can you check if a certain worksheet with title exist in your spreadsheet, using the googlesheets package?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
Cing
  • 806
  • 1
  • 11
  • 29

1 Answers1

2

If you know what the title of the worksheet is, you can check for it this way. Here is a toy example. Load the gapminder test data first:

> library(googlesheets)
> gs_gap() %>% gs_copy(to = "Gapminder")

This will send you to Google to authenticate. Once you do that, close the browser, and return to R. The worksheets available are stored in $ws$ws_title:

> gap <- gs_title("Gapminder")
> gap$ws$ws_title
[1] "Africa"   "Americas" "Asia"     "Europe"   "Oceania" 

So you can check and see if a particular named worksheet is available like this:

> ("Africa" %in% gap$ws$ws_title)
[1] TRUE

There is more info in the googlesheets vignette here which should help you make the connection to your spreadsheet: https://cran.r-project.org/web/packages/googlesheets/vignettes/basic-usage.html

mysteRious
  • 4,102
  • 2
  • 16
  • 36