From 38006d98c5e0de1c9b23f75e617d77c332278aa6 Mon Sep 17 00:00:00 2001 From: jennybc Date: Wed, 22 Jul 2015 21:51:20 -0700 Subject: [PATCH] toggle purling of vignette based on NOT_CRAN what do I see on win-builder? * passes fine, specifically: * "checking running R code from vignettes ... OK" * "checking re-building of vignette outputs ... [30s] OK" * basic_usage.R in the resulting binary package is complete, i.e. it's the one I sent, not the one presumably formed by win-builder above holds for R 3.2.1 and the unstable development version so this approach keeps everything functioning locally but prevents vignette-based errors on win-builder --- vignettes/basic-usage.R | 211 +++++++++++++++++++++++++++++++++++-- vignettes/basic-usage.Rmd | 26 ++--- vignettes/basic-usage.html | 55 +++++----- vignettes/basic-usage.md | 53 +++++----- 4 files changed, 273 insertions(+), 72 deletions(-) diff --git a/vignettes/basic-usage.R b/vignettes/basic-usage.R index 2e1805f..22cf215 100644 --- a/vignettes/basic-usage.R +++ b/vignettes/basic-usage.R @@ -1,13 +1,212 @@ ## ---- echo = FALSE------------------------------------------------------- -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "README-", - purl = FALSE -) if(identical(tolower(Sys.getenv("NOT_CRAN")), "true")) { NOT_CRAN <- TRUE } else { NOT_CRAN <- FALSE } +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + purl = if(NOT_CRAN) TRUE else FALSE +) + +## ----auth, include = FALSE, eval = NOT_CRAN------------------------------ +## I grab the token from the testing directory because that's where it is to be +## found on Travis +token_path <- file.path("..", "tests", "testthat", "googlesheets_token.rds") +suppressMessages(googlesheets::gs_auth(token = token_path, verbose = FALSE)) + +## ----pre-clean, include = FALSE, eval = NOT_CRAN------------------------- +## in case a previous compilation of this document exited uncleanly, pre-clean +## working directory and Google Drive first +googlesheets::gs_vecdel(c("foo", "iris"), verbose = FALSE) +file.remove(c("gapminder.xlsx", "gapminder-africa.csv", "iris")) + +## ----load-package-------------------------------------------------------- +library(googlesheets) +suppressMessages(library(dplyr)) + +## ----list-sheets, eval = NOT_CRAN---------------------------------------- +(my_sheets <- gs_ls()) +# (expect a prompt to authenticate with Google interactively HERE) +my_sheets %>% glimpse() + +## ----copy-gapminder, eval = FALSE---------------------------------------- +# gs_gap() %>% +# gs_copy(to = "Gapminder") + +## ----register-sheet, eval = NOT_CRAN------------------------------------- +gap <- gs_title("Gapminder") +gap + +# Need to access a sheet you do not own? +# Access it by key if you know it! +(GAP_KEY <- gs_gap_key()) +third_party_gap <- GAP_KEY %>% + gs_key() + +# Need to access a sheet you do not own but you have a sharing link? +# Access it by URL! +(GAP_URL <- gs_gap_url()) +third_party_gap <- GAP_URL %>% + gs_url() +# note: registration via URL may not work for "old" sheets + +# Worried that a spreadsheet's registration is out-of-date? +# Re-register it! +gap <- gap %>% gs_gs() + +## ----register-sheet-cran-only, include = FALSE, eval = !NOT_CRAN--------- +# gap <- gs_gap_key() %>% gs_key(lookup = FALSE, visibility = "public") + +## ------------------------------------------------------------------------ +oceania <- gap %>% gs_read(ws = "Oceania") +oceania +str(oceania) +glimpse(oceania) + +## ------------------------------------------------------------------------ +gap %>% gs_read(ws = 2, range = "A1:D8") +gap %>% gs_read(ws = "Europe", range = cell_rows(1:4)) +gap %>% gs_read(ws = "Europe", range = cell_rows(100:103), col_names = FALSE) +gap %>% gs_read(ws = "Africa", range = cell_cols(1:4)) +gap %>% gs_read(ws = "Asia", range = cell_limits(c(1, 4), c(5, NA))) + +## ----csv-list-and-cell-feed---------------------------------------------- +# Get the data for worksheet "Oceania": the super-fast csv way +oceania_csv <- gap %>% gs_read_csv(ws = "Oceania") +str(oceania_csv) +oceania_csv + +# Get the data for worksheet "Oceania": the less-fast tabular way ("list feed") +oceania_list_feed <- gap %>% gs_read_listfeed(ws = "Oceania") +str(oceania_list_feed) +oceania_list_feed + +# Get the data for worksheet "Oceania": the slow cell-by-cell way ("cell feed") +oceania_cell_feed <- gap %>% gs_read_cellfeed(ws = "Oceania") +str(oceania_cell_feed) +oceania_cell_feed + +## ------------------------------------------------------------------------ +jfun <- function(readfun) + system.time(do.call(readfun, list(gs_gap(), ws = "Africa", verbose = FALSE))) +readfuns <- c("gs_read_csv", "gs_read_listfeed", "gs_read_cellfeed") +readfuns <- sapply(readfuns, get, USE.NAMES = TRUE) +sapply(readfuns, jfun) + +## ----post-processing----------------------------------------------------- +# Reshape: instead of one row per cell, make a nice rectangular data.frame +australia_cell_feed <- gap %>% + gs_read_cellfeed(ws = "Oceania", range = "A1:F13") +str(australia_cell_feed) +oceania_cell_feed +australia_reshaped <- australia_cell_feed %>% gs_reshape_cellfeed() +str(australia_reshaped) +australia_reshaped + +# Example: first 3 rows +gap_3rows <- gap %>% gs_read_cellfeed("Europe", range = cell_rows(1:3)) +gap_3rows %>% head() + +# convert to a data.frame (by default, column names found in first row) +gap_3rows %>% gs_reshape_cellfeed() + +# arbitrary cell range, column names no longer available in first row +gap %>% + gs_read_cellfeed("Oceania", range = "D12:F15") %>% + gs_reshape_cellfeed(col_names = FALSE) + +# arbitrary cell range, direct specification of column names +gap %>% + gs_read_cellfeed("Oceania", range = cell_limits(c(2, 1), c(5, 3))) %>% + gs_reshape_cellfeed(col_names = paste("thing", c("one", "two", "three"), + sep = "_")) + +## ------------------------------------------------------------------------ +# Example: first row only +gap_1row <- gap %>% gs_read_cellfeed("Europe", range = cell_rows(1)) +gap_1row + +# convert to a named character vector +gap_1row %>% gs_simplify_cellfeed() + +# Example: single column +gap_1col <- gap %>% gs_read_cellfeed("Europe", range = cell_cols(3)) +gap_1col + +# convert to a un-named character vector and drop the variable name +gap_1col %>% gs_simplify_cellfeed(notation = "none", col_names = TRUE) + +## ----new-sheet, eval = NOT_CRAN------------------------------------------ +foo <- gs_new("foo") +foo + +## ----edit-cells, eval = NOT_CRAN----------------------------------------- +## foo <- gs_new("foo") +## initialize the worksheets +foo <- foo %>% gs_ws_new("edit_cells") +foo <- foo %>% gs_ws_new("add_row") + +## add first six rows of iris data (and var names) into a blank sheet +foo <- foo %>% + gs_edit_cells(ws = "edit_cells", input = head(iris), trim = TRUE) + +## initialize sheet with column headers and one row of data +## the list feed is picky about this +foo <- foo %>% + gs_edit_cells(ws = "add_row", input = head(iris, 1), trim = TRUE) +## add the next 5 rows of data ... careful not to go too fast +for(i in 2:6) { + foo <- foo %>% gs_add_row(ws = "add_row", input = iris[i, ]) + Sys.sleep(0.3) +} + +## let's inspect out work +foo %>% gs_read(ws = "edit_cells") +foo %>% gs_read(ws = "add_row") + +## ----delete-sheet, eval = NOT_CRAN--------------------------------------- +gs_delete(foo) + +## ----new-sheet-from-file, eval = NOT_CRAN-------------------------------- +iris %>% + head(5) %>% + write.csv("iris.csv", row.names = FALSE) +iris_ss <- gs_upload("iris.csv") +iris_ss +iris_ss %>% gs_read() +file.remove("iris.csv") + +## ----new-sheet-from-xlsx, eval = NOT_CRAN-------------------------------- +gap_xlsx <- gs_upload(system.file("mini-gap.xlsx", package = "googlesheets")) +gap_xlsx +gap_xlsx %>% gs_read(ws = "Asia") + +## ----delete-moar-sheets, eval = NOT_CRAN--------------------------------- +gs_vecdel(c("iris", "mini-gap")) +## achieves same as: +## gs_delete(iris_ss) +## gs_delete(gap_xlsx) + +## ----export-sheet-as-csv, eval = NOT_CRAN-------------------------------- +gs_title("Gapminder") %>% + gs_download(ws = "Africa", to = "gapminder-africa.csv") +## is it there? yes! +read.csv("gapminder-africa.csv") %>% head() + +## ----export-sheet-as-xlsx, eval = NOT_CRAN------------------------------- +gs_title("Gapminder") %>% + gs_download(to = "gapminder.xlsx") + +## ----clean-exported-files, eval = NOT_CRAN------------------------------- +file.remove(c("gapminder.xlsx", "gapminder-africa.csv")) + +## ----gs_auth, eval = FALSE----------------------------------------------- +# # Give googlesheets permission to access your spreadsheets and google drive +# gs_auth() + +## ----gs_user------------------------------------------------------------- +user_session_info <- gs_user() +user_session_info diff --git a/vignettes/basic-usage.Rmd b/vignettes/basic-usage.Rmd index 497d6af..57054f5 100644 --- a/vignettes/basic-usage.Rmd +++ b/vignettes/basic-usage.Rmd @@ -13,17 +13,16 @@ vignette: > --- ```{r, echo = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "README-", - purl = FALSE -) if(identical(tolower(Sys.getenv("NOT_CRAN")), "true")) { NOT_CRAN <- TRUE } else { NOT_CRAN <- FALSE } +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + purl = if(NOT_CRAN) TRUE else FALSE +) ``` ```{r auth, include = FALSE, eval = NOT_CRAN} @@ -34,20 +33,22 @@ suppressMessages(googlesheets::gs_auth(token = token_path, verbose = FALSE)) ``` ```{r pre-clean, include = FALSE, eval = NOT_CRAN} -## if a previous compilation of this document leaves anything behind, i.e. if it -## aborts, clean up Google Drive first +## in case a previous compilation of this document exited uncleanly, pre-clean +## working directory and Google Drive first googlesheets::gs_vecdel(c("foo", "iris"), verbose = FALSE) file.remove(c("gapminder.xlsx", "gapminder-africa.csv", "iris")) ``` -```{r load package} +First we load the `googlesheets` package and `dplyr`, from which we use the `%>%` pipe operator, among other things. `googlesheets` usage *does not require* you to use `%>%` though it was certainly designed to be pipe-friendly. This vignette uses pipes but you will find that all the examples in the help files use base R only. + +```{r load-package} library(googlesheets) suppressMessages(library(dplyr)) ``` ### See some spreadsheets you can access -The `gs_ls()` function returns the sheets you would see in your Google Sheets home screen: . This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication). +The `gs_ls()` function returns the sheets you would see in your Google Sheets home screen: . This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you have visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication). ```{r list-sheets, eval = NOT_CRAN} (my_sheets <- gs_ls()) @@ -100,7 +101,6 @@ gap <- gap %>% gs_gs() gap <- gs_gap_key() %>% gs_key(lookup = FALSE, visibility = "public") ``` - The registration functions `gs_title()`, `gs_key()`, `gs_url()`, and `gs_gs()` return a registered sheet as a `googlesheet` object, which is the first argument to practically every function in this package. Likewise, almost every function returns a freshly registered `googlesheet` object, ready to be stored or piped into the next command. *We export a utility function, `extract_key_from_url()`, to help you get and store the key from a browser URL. Registering via browser URL is fine, but registering by key is probably a better idea in the long-run.* @@ -242,7 +242,7 @@ There are two ways to edit cells within an existing worksheet of an existing spr If you have the choice, `gs_add_row()` is faster, but it can only be used when your data occupies a very neat rectangle in the upper left corner of the sheet. It relies on the [list feed](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds). `gs_edit_cells()` relies on [batch editing](https://developers.google.com/google-apps/spreadsheets/#updating_multiple_cells_with_a_batch_request) on the [cell feed](https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds). -We'll work within the completely empty sheet created above, `foo`. If your edit populates the sheet with everything it should have, set `trim = TRUE` and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and any future consumption via the cell feed will be much faster. +We'll work within the completely empty sheet created above, `foo`. If your edit populates the sheet with everything it should have, set `trim = TRUE` and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and future consumption via the cell feed will potentially be faster. ```{r edit-cells, eval = NOT_CRAN} ## foo <- gs_new("foo") @@ -344,7 +344,7 @@ file.remove(c("gapminder.xlsx", "gapminder-africa.csv")) ### Authorization using OAuth2 -If you use a function that requires authentication, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so: +If you use a function that requires authorization, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so: ```{r gs_auth, eval = FALSE} # Give googlesheets permission to access your spreadsheets and google drive diff --git a/vignettes/basic-usage.html b/vignettes/basic-usage.html index aa2fb29..40c6bbd 100644 --- a/vignettes/basic-usage.html +++ b/vignettes/basic-usage.html @@ -10,7 +10,7 @@ - + googlesheets Basic Usage @@ -54,7 +54,7 @@
@@ -73,16 +73,17 @@

2015-07-20

+

First we load the googlesheets package and dplyr, from which we use the %>% pipe operator, among other things. googlesheets usage does not require you to use %>% though it was certainly designed to be pipe-friendly. This vignette uses pipes but you will find that all the examples in the help files use base R only.

library(googlesheets)
 suppressMessages(library(dplyr))

See some spreadsheets you can access

-

The gs_ls() function returns the sheets you would see in your Google Sheets home screen: https://docs.google.com/spreadsheets/. This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication).

+

The gs_ls() function returns the sheets you would see in your Google Sheets home screen: https://docs.google.com/spreadsheets/. This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you have visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication).

(my_sheets <- gs_ls())
 #> Source: local data frame [42 x 10]
 #> 
 #>                 sheet_title        author perm version             updated
-#> 1  Copy of Twitter Archive…   joannazhaoo    r     new 2015-07-20 22:13:25
+#> 1  Copy of Twitter Archive…   joannazhaoo    r     new 2015-07-23 01:39:25
 #> 2               gas_mileage      woo.kara    r     new 2015-07-20 01:08:07
 #> 3               TAGS v6.0ns     m.hawksey    r     new 2015-07-14 08:59:57
 #> 4  test-gs-jenny-121c66d79…      gspreadr   rw     new 2015-07-06 17:08:26
@@ -103,7 +104,7 @@ 

See some spreadsheets you can access

#> $ author (chr) "joannazhaoo", "woo.kara", "m.hawksey", "gspreadr"... #> $ perm (chr) "r", "r", "r", "rw", "rw", "r", "rw", "r", "r", "r... #> $ version (chr) "new", "new", "new", "new", "new", "new", "new", "... -#> $ updated (time) 2015-07-20 22:13:25, 2015-07-20 01:08:07, 2015-07... +#> $ updated (time) 2015-07-23 01:39:25, 2015-07-20 01:08:07, 2015-07... #> $ sheet_key (chr) "1DoMXh2m3FGPoZAle9vnzg763D9FESTU506iqWkUTwtE", "1... #> $ ws_feed (chr) "https://spreadsheets.google.com/feeds/worksheets/... #> $ alternate (chr) "https://docs.google.com/spreadsheets/d/1DoMXh2m3F... @@ -127,7 +128,7 @@

Register a spreadsheet

gap #> Spreadsheet title: Gapminder #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:19:31 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:01 GMT #> Date of last spreadsheet update: 2015-03-23 20:34:08 GMT #> visibility: private #> permissions: rw @@ -369,9 +370,9 @@

Quick speed comparison

readfuns <- sapply(readfuns, get, USE.NAMES = TRUE) sapply(readfuns, jfun) #> gs_read_csv gs_read_listfeed gs_read_cellfeed -#> user.self 0.034 0.143 1.016 -#> sys.self 0.001 0.021 0.053 -#> elapsed 1.029 0.782 2.178 +#> user.self 0.032 0.155 1.091 +#> sys.self 0.001 0.016 0.051 +#> elapsed 1.224 0.715 2.515 #> user.child 0.000 0.000 0.000 #> sys.child 0.000 0.000 0.000
@@ -569,8 +570,8 @@

Create sheets

foo #> Spreadsheet title: foo #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:19:51 GMT -#> Date of last spreadsheet update: 2015-07-20 22:19:48 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:22 GMT +#> Date of last spreadsheet update: 2015-07-23 01:41:20 GMT #> visibility: private #> permissions: rw #> version: new @@ -579,8 +580,8 @@

Create sheets

#> (Title): (Nominal worksheet extent as rows x columns) #> Sheet1: 1000 x 26 #> -#> Key: 1OBRGUa3d4RkwXJcnbyN8f0fa1WqHCjM34-Ie_PWyaB0 -#> Browser URL: https://docs.google.com/spreadsheets/d/1OBRGUa3d4RkwXJcnbyN8f0fa1WqHCjM34-Ie_PWyaB0/ +#> Key: 1jDMiJ3DTdSexNiFH1bz9VrNKHulxEi2gymcuTt49d9Y +#> Browser URL: https://docs.google.com/spreadsheets/d/1jDMiJ3DTdSexNiFH1bz9VrNKHulxEi2gymcuTt49d9Y/

By default, there will be an empty worksheet called “Sheet1”, but you can control it’s title, extent, and initial data with additional arguments to gs_new() (see gs_edit_cells() in the next section). You can also add, rename, and delete worksheets within an existing sheet via gs_ws_new(), gs_ws_rename(), and gs_ws_delete(). Copy an entire spreadsheet with gs_copy().

@@ -591,7 +592,7 @@

Edit cells

  • gs_add_row() can add a new row to the bottom of an existing cell rectangle
  • If you have the choice, gs_add_row() is faster, but it can only be used when your data occupies a very neat rectangle in the upper left corner of the sheet. It relies on the list feed. gs_edit_cells() relies on batch editing on the cell feed.

    -

    We’ll work within the completely empty sheet created above, foo. If your edit populates the sheet with everything it should have, set trim = TRUE and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and any future consumption via the cell feed will be much faster.

    +

    We’ll work within the completely empty sheet created above, foo. If your edit populates the sheet with everything it should have, set trim = TRUE and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and future consumption via the cell feed will potentially be faster.

    ## foo <- gs_new("foo")
     ## initialize the worksheets
     foo <- foo %>% gs_ws_new("edit_cells")
    @@ -679,8 +680,8 @@ 

    Upload delimited files or Excel workbooks

    iris_ss #> Spreadsheet title: iris #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:20:23 GMT -#> Date of last spreadsheet update: 2015-07-20 22:20:21 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:59 GMT +#> Date of last spreadsheet update: 2015-07-23 01:41:57 GMT #> visibility: private #> permissions: rw #> version: new @@ -689,8 +690,8 @@

    Upload delimited files or Excel workbooks

    #> (Title): (Nominal worksheet extent as rows x columns) #> iris: 1000 x 26 #> -#> Key: 14EJWUvfIjRW7Z-pIStWfkG7XvhJKVBU9gxVIrnddTJM -#> Browser URL: https://docs.google.com/spreadsheets/d/14EJWUvfIjRW7Z-pIStWfkG7XvhJKVBU9gxVIrnddTJM/ +#> Key: 1siYLOsSq7CVZXKby3gMtc59Rlp69-cEYA6g-xtZcok4 +#> Browser URL: https://docs.google.com/spreadsheets/d/1siYLOsSq7CVZXKby3gMtc59Rlp69-cEYA6g-xtZcok4/ iris_ss %>% gs_read() #> Accessing worksheet titled "iris" #> Source: local data frame [5 x 5] @@ -709,8 +710,8 @@

    Upload delimited files or Excel workbooks

    gap_xlsx #> Spreadsheet title: mini-gap #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:20:29 GMT -#> Date of last spreadsheet update: 2015-07-20 22:20:27 GMT +#> Date of googlesheets registration: 2015-07-23 01:42:04 GMT +#> Date of last spreadsheet update: 2015-07-23 01:42:02 GMT #> visibility: private #> permissions: rw #> version: new @@ -723,8 +724,8 @@

    Upload delimited files or Excel workbooks

    #> Europe: 1000 x 26 #> Oceania: 1000 x 26 #> -#> Key: 1UPE1nDcjsm5qiD1dsuWMcgUahMQyXRE6ofb9boaZ2iE -#> Browser URL: https://docs.google.com/spreadsheets/d/1UPE1nDcjsm5qiD1dsuWMcgUahMQyXRE6ofb9boaZ2iE/ +#> Key: 1e0Kjnwdrx7RSVxKnpcKVqY4MpZOq1Q-853Dd4wyff6Y +#> Browser URL: https://docs.google.com/spreadsheets/d/1e0Kjnwdrx7RSVxKnpcKVqY4MpZOq1Q-853Dd4wyff6Y/ gap_xlsx %>% gs_read(ws = "Asia") #> Accessing worksheet titled "Asia" #> Source: local data frame [5 x 6] @@ -777,7 +778,7 @@

    Download sheets as csv, pdf, or xlsx file

    Authorization using OAuth2

    -

    If you use a function that requires authentication, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so:

    +

    If you use a function that requires authorization, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so:

    # Give googlesheets permission to access your spreadsheets and google drive
     gs_auth() 

    Use gs_auth(new_user = TRUE), to force the process to begin anew. Otherwise, the credentials left behind will be used to refresh your access token as needed.

    @@ -785,9 +786,9 @@

    Authorization using OAuth2

    user_session_info <- gs_user()
     #>           displayName: google sheets
     #>          emailAddress: gspreadr@gmail.com
    -#>                  date: 2015-07-20 22:19:28 GMT
    +#>                  date: 2015-07-23 01:40:58 GMT
     #>          access token: valid
    -#>  peek at access token: ya29....oOPjQ
    +#>  peek at access token: ya29....ZuaTw
     #> peek at refresh token: 1/zNh...ATCKT
     user_session_info
     #> $displayName
    @@ -797,13 +798,13 @@ 

    Authorization using OAuth2

    #> [1] "gspreadr@gmail.com" #> #> $date -#> [1] "2015-07-20 22:19:28 GMT" +#> [1] "2015-07-23 01:40:58 GMT" #> #> $token_valid #> [1] TRUE #> #> $peek_acc -#> [1] "ya29....oOPjQ" +#> [1] "ya29....ZuaTw" #> #> $peek_ref #> [1] "1/zNh...ATCKT"
    diff --git a/vignettes/basic-usage.md b/vignettes/basic-usage.md index c649521..077e3ed 100644 --- a/vignettes/basic-usage.md +++ b/vignettes/basic-usage.md @@ -8,6 +8,8 @@ Jenny Bryan, Joanna Zhao +First we load the `googlesheets` package and `dplyr`, from which we use the `%>%` pipe operator, among other things. `googlesheets` usage *does not require* you to use `%>%` though it was certainly designed to be pipe-friendly. This vignette uses pipes but you will find that all the examples in the help files use base R only. + ```r library(googlesheets) @@ -16,7 +18,7 @@ suppressMessages(library(dplyr)) ### See some spreadsheets you can access -The `gs_ls()` function returns the sheets you would see in your Google Sheets home screen: . This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication). +The `gs_ls()` function returns the sheets you would see in your Google Sheets home screen: . This should include sheets that you own and may also show sheets owned by others but that you are permitted to access, if you have visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication). ```r @@ -24,7 +26,7 @@ The `gs_ls()` function returns the sheets you would see in your Google Sheets ho #> Source: local data frame [42 x 10] #> #> sheet_title author perm version updated -#> 1 Copy of Twitter Archive… joannazhaoo r new 2015-07-20 22:13:25 +#> 1 Copy of Twitter Archive… joannazhaoo r new 2015-07-23 01:39:25 #> 2 gas_mileage woo.kara r new 2015-07-20 01:08:07 #> 3 TAGS v6.0ns m.hawksey r new 2015-07-14 08:59:57 #> 4 test-gs-jenny-121c66d79… gspreadr rw new 2015-07-06 17:08:26 @@ -45,7 +47,7 @@ my_sheets %>% glimpse() #> $ author (chr) "joannazhaoo", "woo.kara", "m.hawksey", "gspreadr"... #> $ perm (chr) "r", "r", "r", "rw", "rw", "r", "rw", "r", "r", "r... #> $ version (chr) "new", "new", "new", "new", "new", "new", "new", "... -#> $ updated (time) 2015-07-20 22:13:25, 2015-07-20 01:08:07, 2015-07... +#> $ updated (time) 2015-07-23 01:39:25, 2015-07-20 01:08:07, 2015-07... #> $ sheet_key (chr) "1DoMXh2m3FGPoZAle9vnzg763D9FESTU506iqWkUTwtE", "1... #> $ ws_feed (chr) "https://spreadsheets.google.com/feeds/worksheets/... #> $ alternate (chr) "https://docs.google.com/spreadsheets/d/1DoMXh2m3F... @@ -80,7 +82,7 @@ gap <- gs_title("Gapminder") gap #> Spreadsheet title: Gapminder #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:19:31 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:01 GMT #> Date of last spreadsheet update: 2015-03-23 20:34:08 GMT #> visibility: private #> permissions: rw @@ -128,7 +130,6 @@ gap <- gap %>% gs_gs() - The registration functions `gs_title()`, `gs_key()`, `gs_url()`, and `gs_gs()` return a registered sheet as a `googlesheet` object, which is the first argument to practically every function in this package. Likewise, almost every function returns a freshly registered `googlesheet` object, ready to be stored or piped into the next command. *We export a utility function, `extract_key_from_url()`, to help you get and store the key from a browser URL. Registering via browser URL is fine, but registering by key is probably a better idea in the long-run.* @@ -345,9 +346,9 @@ readfuns <- c("gs_read_csv", "gs_read_listfeed", "gs_read_cellfeed") readfuns <- sapply(readfuns, get, USE.NAMES = TRUE) sapply(readfuns, jfun) #> gs_read_csv gs_read_listfeed gs_read_cellfeed -#> user.self 0.034 0.143 1.016 -#> sys.self 0.001 0.021 0.053 -#> elapsed 1.029 0.782 2.178 +#> user.self 0.032 0.155 1.091 +#> sys.self 0.001 0.016 0.051 +#> elapsed 1.224 0.715 2.515 #> user.child 0.000 0.000 0.000 #> sys.child 0.000 0.000 0.000 ``` @@ -558,8 +559,8 @@ foo <- gs_new("foo") foo #> Spreadsheet title: foo #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:19:51 GMT -#> Date of last spreadsheet update: 2015-07-20 22:19:48 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:22 GMT +#> Date of last spreadsheet update: 2015-07-23 01:41:20 GMT #> visibility: private #> permissions: rw #> version: new @@ -568,8 +569,8 @@ foo #> (Title): (Nominal worksheet extent as rows x columns) #> Sheet1: 1000 x 26 #> -#> Key: 1OBRGUa3d4RkwXJcnbyN8f0fa1WqHCjM34-Ie_PWyaB0 -#> Browser URL: https://docs.google.com/spreadsheets/d/1OBRGUa3d4RkwXJcnbyN8f0fa1WqHCjM34-Ie_PWyaB0/ +#> Key: 1jDMiJ3DTdSexNiFH1bz9VrNKHulxEi2gymcuTt49d9Y +#> Browser URL: https://docs.google.com/spreadsheets/d/1jDMiJ3DTdSexNiFH1bz9VrNKHulxEi2gymcuTt49d9Y/ ``` By default, there will be an empty worksheet called "Sheet1", but you can control it's title, extent, and initial data with additional arguments to `gs_new()` (see `gs_edit_cells()` in the next section). You can also add, rename, and delete worksheets within an existing sheet via `gs_ws_new()`, `gs_ws_rename()`, and `gs_ws_delete()`. Copy an entire spreadsheet with `gs_copy()`. @@ -583,7 +584,7 @@ There are two ways to edit cells within an existing worksheet of an existing spr If you have the choice, `gs_add_row()` is faster, but it can only be used when your data occupies a very neat rectangle in the upper left corner of the sheet. It relies on the [list feed](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds). `gs_edit_cells()` relies on [batch editing](https://developers.google.com/google-apps/spreadsheets/#updating_multiple_cells_with_a_batch_request) on the [cell feed](https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds). -We'll work within the completely empty sheet created above, `foo`. If your edit populates the sheet with everything it should have, set `trim = TRUE` and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and any future consumption via the cell feed will be much faster. +We'll work within the completely empty sheet created above, `foo`. If your edit populates the sheet with everything it should have, set `trim = TRUE` and we will resize the sheet to match the data. Then the nominal worksheet extent is much more informative (vs. the default of 1000 rows and 26 columns) and future consumption via the cell feed will potentially be faster. ```r @@ -686,8 +687,8 @@ iris_ss <- gs_upload("iris.csv") iris_ss #> Spreadsheet title: iris #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:20:23 GMT -#> Date of last spreadsheet update: 2015-07-20 22:20:21 GMT +#> Date of googlesheets registration: 2015-07-23 01:41:59 GMT +#> Date of last spreadsheet update: 2015-07-23 01:41:57 GMT #> visibility: private #> permissions: rw #> version: new @@ -696,8 +697,8 @@ iris_ss #> (Title): (Nominal worksheet extent as rows x columns) #> iris: 1000 x 26 #> -#> Key: 14EJWUvfIjRW7Z-pIStWfkG7XvhJKVBU9gxVIrnddTJM -#> Browser URL: https://docs.google.com/spreadsheets/d/14EJWUvfIjRW7Z-pIStWfkG7XvhJKVBU9gxVIrnddTJM/ +#> Key: 1siYLOsSq7CVZXKby3gMtc59Rlp69-cEYA6g-xtZcok4 +#> Browser URL: https://docs.google.com/spreadsheets/d/1siYLOsSq7CVZXKby3gMtc59Rlp69-cEYA6g-xtZcok4/ iris_ss %>% gs_read() #> Accessing worksheet titled "iris" #> Source: local data frame [5 x 5] @@ -721,8 +722,8 @@ gap_xlsx <- gs_upload(system.file("mini-gap.xlsx", package = "googlesheets")) gap_xlsx #> Spreadsheet title: mini-gap #> Spreadsheet author: gspreadr -#> Date of googlesheets registration: 2015-07-20 22:20:29 GMT -#> Date of last spreadsheet update: 2015-07-20 22:20:27 GMT +#> Date of googlesheets registration: 2015-07-23 01:42:04 GMT +#> Date of last spreadsheet update: 2015-07-23 01:42:02 GMT #> visibility: private #> permissions: rw #> version: new @@ -735,8 +736,8 @@ gap_xlsx #> Europe: 1000 x 26 #> Oceania: 1000 x 26 #> -#> Key: 1UPE1nDcjsm5qiD1dsuWMcgUahMQyXRE6ofb9boaZ2iE -#> Browser URL: https://docs.google.com/spreadsheets/d/1UPE1nDcjsm5qiD1dsuWMcgUahMQyXRE6ofb9boaZ2iE/ +#> Key: 1e0Kjnwdrx7RSVxKnpcKVqY4MpZOq1Q-853Dd4wyff6Y +#> Browser URL: https://docs.google.com/spreadsheets/d/1e0Kjnwdrx7RSVxKnpcKVqY4MpZOq1Q-853Dd4wyff6Y/ gap_xlsx %>% gs_read(ws = "Asia") #> Accessing worksheet titled "Asia" #> Source: local data frame [5 x 6] @@ -810,7 +811,7 @@ file.remove(c("gapminder.xlsx", "gapminder-africa.csv")) ### Authorization using OAuth2 -If you use a function that requires authentication, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so: +If you use a function that requires authorization, it will be auto-triggered. But you can also initiate the process explicitly if you wish, like so: ```r @@ -827,9 +828,9 @@ The function `gs_user()` will print and return some information about the curren user_session_info <- gs_user() #> displayName: google sheets #> emailAddress: gspreadr@gmail.com -#> date: 2015-07-20 22:19:28 GMT +#> date: 2015-07-23 01:40:58 GMT #> access token: valid -#> peek at access token: ya29....oOPjQ +#> peek at access token: ya29....ZuaTw #> peek at refresh token: 1/zNh...ATCKT user_session_info #> $displayName @@ -839,13 +840,13 @@ user_session_info #> [1] "gspreadr@gmail.com" #> #> $date -#> [1] "2015-07-20 22:19:28 GMT" +#> [1] "2015-07-23 01:40:58 GMT" #> #> $token_valid #> [1] TRUE #> #> $peek_acc -#> [1] "ya29....oOPjQ" +#> [1] "ya29....ZuaTw" #> #> $peek_ref #> [1] "1/zNh...ATCKT"