Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active September 19, 2018 13:27
Show Gist options
  • Save matt-dray/a0b2e66ed4f4f6612520e9a759e70606 to your computer and use it in GitHub Desktop.
Save matt-dray/a0b2e66ed4f4f6612520e9a759e70606 to your computer and use it in GitHub Desktop.
Basic functions from the googlesheets package for R
# Basic googlesheets functions
# Jan 2018
# https://github.com/jennybc/googlesheets
# Browser sign-in required on first function execution
# 1. Load package ----
#install.packages(googlesheets)
library(googlesheets)
# 2. Create and amend a Google sheet ----
# New Google Sheet
googlesheets::gs_new(
title = "Important beavers data", # title for the spreadsheet
ws_title = "worksheet1", # worksheet name
input = beaver1[1:5, ], # data to input
)
# Append data to worksheet
googlesheets::gs_add_row(
ss = beavers_data, # spreadsheet where it will be added
ws = "worksheet1", # worksheet to add the data to
input = beaver2[1:5, ] # data to input
)
# Add new worksheet
googlesheets::gs_ws_new(
ss = beavers_data, # spreadsheet where it will be added
ws_title = "worksheet2", # name of new worksheet
input = beaver2[5:10, ] # data to input
)
# 3. Register an existing Google Sheet ----
# Create 'googlesheet' class object to interact with the file
beavers_data <- googlesheet::gs_title(x = "beavers data")
# 4. View ----
# In browser
googlesheets::gs_browse(beavers_data)
# Download
googlesheets::gs_download(
from = beavers_data, # registered googlesheets object
to = "data/beaver1_test.csv" # filepath
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment