knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

"reprex" is short for "reproducible example". A reprex is very helpful when reporting a bug or requesting a new feature. The reprex package helps with some of the fiddly mechanics of making a self-contained, well-formatted reprex.

You might worry about some awkward things when using reprex with googlesheets4:

Here we show various ways this can work, if rough order of preference.

Use a public example Sheet

If you can make your point with one of the example Sheets, exposed via gs4_examples() and gs4_example(), do so! You can call gs4_deauth() explicitly in your reprex to shut down any attempt to get a token.

library(googlesheets4)

gs4_deauth()

# put the googlesheets4 code you want to reproduce below here
# the following is just an example, replace it with your own code
gs4_example("mini-gap") %>% 
  gs4_get()

Create a Sheet and make it world-readable

If you can create an example Sheet that makes your point and make it readable by "anyone with a link", do so! You can call gs4_deauth() explicitly in your reprex to shut down any attempt to get a token.

How do you make a Sheet world-readable? Do this setup once! It should not be part of your reprex. Two options:

Now make a reprex just like we do with the official example Sheets:

library(googlesheets4)

gs4_deauth()

# put the googlesheets4 code you want to reproduce below here
# the following is just an example, replace it with your own code
gs4_get("YOUR_SHEET_ID_OR_URL_GOES_HERE")

Grant access to specific user(s)

If you can't create a world-readable example Sheet, perhaps you can still share one with specific individuals, such as a package maintainer. How to share with specific user(s):

See the next section for advice on your reprex code.

Use a private Sheet

reprex::reprex() eventually runs your code in a fresh, non-interactive R session. You won't be there to do anything about auth, like select the right identity or approve the use of a cached token.

This general situation is documented in the gargle vignette Non-interactive auth. But here's the short version:

Here's an example of a snippet suitable for reprex::reprex(), assuming the user has successfully run it once interactively, so there's a cached token for "jane_doe@example.com".

library(googlesheets4)

gs4_auth(email = "jane_doe@example.com")

# put the googlesheets4 code you want to reproduce below here
# the following is just an example, replace it with your own code
ssid <- "some_very_long_string_of_letters_and_digits"
gs4_get(ssid)

If you're reluctant to reveal your email address and/or the spreadsheet id, you can use special comments to create a hidden chunk and a visible body chunk. If the Sheet is private and no one else will be able to access it anyway, this is still a good option to show exactly what you're seeing locally.

library(googlesheets4)

#+ include = FALSE
# code here is executed but the results won't appear in rendered reprex
gs4_auth(email = "jane_doe@example.com")
ssid <- "some_very_long_string_of_letters_and_digits"

#+ include = TRUE
# put the googlesheets4 code you want to reproduce below here
# the following is just an example, replace it with your own code
gs4_get(ssid)


jennybc/googlesheets2 documentation built on Dec. 10, 2023, 12:56 a.m.