Skip to content

Instantly share code, notes, and snippets.

@btupper
Last active June 11, 2024 20:01
Show Gist options
  • Save btupper/7de35edb1ebebb3a852016acce6214c8 to your computer and use it in GitHub Desktop.
Save btupper/7de35edb1ebebb3a852016acce6214c8 to your computer and use it in GitHub Desktop.
Using googlesheets4 interactively
# https://drive.google.com/drive/folders/1vSdFzlbdT4khWeileTmN8gycNCINT2gS?usp=share_link
suppressPackageStartupMessages({
library(googlesheets4)
library(dplyr)
})
# authorize
gs4_auth()
# the sandbox
uri = "https://docs.google.com/spreadsheets/d/1wu6gy2EMMKbN5vZYnmpoxrj3Rs52ubZvzr5lm9k8frQ/edit?gid=75930542#gid=75930542"
# the ss object
ss = gs4_get(uri)
ss
# read a sheet - faster if you tell it what to expect
x = read_sheet(ss, col_types = "nnnnc")
glimpse(x)
# add a blank sheet
ss = sheet_add(ss, sheet = "Ben")
# put some data there
ss = range_write(ss, faithful, sheet = "Ben")
# read it back
y = read_sheet(ss, col_types = "nn", sheet = "Ben")
glimpse(y)
# rename the sheet
ss = sheet_rename(ss, sheet = "Ben", "btupper")
gs4_deauth()
@btupper
Copy link
Author

btupper commented Jun 11, 2024

Update the URI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment