Last active
September 19, 2018 13:27
-
-
Save matt-dray/a0b2e66ed4f4f6612520e9a759e70606 to your computer and use it in GitHub Desktop.
Basic functions from the googlesheets package for R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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