diff --git a/README.Rmd b/README.Rmd index 109cff1..1053ed2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -65,22 +65,32 @@ What other ideas do you have? devtools::install_github("jennybc/googlesheets") ``` +*We plan to submit to CRAN in late May or early June 2015, so feedback on functionality and usability is especially valuable to us now!* + ### Take a look at the vignette -This README is arguably as or more useful as the vignette and both are still under development. But feel free to [check out the current state of the vignette](http://htmlpreview.github.io/?https://raw.githubusercontent.com/jennybc/googlesheets/master/vignettes/basic-usage.html). +No, actually, __don't__. This README is much more current than the vignette, though that will have to change soon! + +If you insist, [check out the current state of the vignette](http://htmlpreview.github.io/?https://raw.githubusercontent.com/jennybc/googlesheets/master/vignettes/basic-usage.html). ### Load googlesheets -`googlesheets` is designed for use with the `%>%` pipe operator and, to a lesser extent, the data-wrangling mentality of `dplyr`. The examples here use both, but we'll soon develop a vignette that shows usage with plain vanilla R. `googlesheets` uses `dplyr` internally but does not require the user to do so. +`googlesheets` is designed for use with the `%>%` pipe operator and, to a lesser extent, the data-wrangling mentality of [`dplyr`](http://cran.r-project.org/web/packages/dplyr/index.html). This README uses both, but the examples in the help files emphasize usage with plain vanilla R, if that's how you roll. `googlesheets` uses `dplyr` internally but does not require the user to do so. You can make the `%>%` pipe operator availble in your own work by loading [`dplyr`](http://cran.r-project.org/web/packages/dplyr/index.html) or [`magrittr`](http://cran.r-project.org/web/packages/magrittr/index.html). ```{r load-package} library("googlesheets") suppressMessages(library("dplyr")) ``` +### Function naming convention + +*implementation not yet 100% complete ... but we'll get there soon* + +All functions start with `gs_`, which plays nicely with tab completion in RStudio, for example. If the function has something to do with worksheets or tabs within a spreadsheet, it will start with `gs_ws_`. + ### 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, especially if you have clicked on a link shared by the owner. 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 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} (my_sheets <- gs_ls()) @@ -88,12 +98,24 @@ The `gs_ls()` function returns the sheets you would see in your Google Sheets ho my_sheets %>% glimpse() ``` +### Get a Google spreadsheet to practice with + +If you don't have any suitable Google Sheets lying around, or if you just want to follow along verbatim with this vignette, this bit of code will copy a sheet from the `googlesheets` Google user into your Drive. The sheet holds some of the [Gapminder data](https://github.com/jennybc/gapminder). + +```{r copy-gapminder, eval = FALSE} +gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA" +gs_copy(gs_key(gap_key), to = "Gapminder") +``` + +If that seems to have worked, go check that you see a sheet named "Gapminder" listed in your Google Sheets home screen: . You could also run `gs_ls()` again and make sure the Gapminder sheet is listed. + ### Register a spreadsheet -If you plan to consume data from a sheet or edit it, you must first register it. Basically this is where `googlesheets` makes a note of important info about the sheet that's needed to access via the Sheets API. Once registered, you can print the result to get some basic info about the sheet. +If you plan to consume data from a sheet or edit it, you must first __register__ it. This is how `googlesheets` records important info about the sheet that is required downstream by the Google Sheets or Google Drive APIs. Once registered, you can print the result to get some basic info about the sheet. + +`googlesheets` provides several registration functions. Specifying the sheet by title? Use `gs_title()`. By key? Use `gs_key()`. You get the idea. ```{r register-sheet} -# Hey let's look at the Gapminder data gap <- gs_title("Gapminder") gap @@ -102,39 +124,29 @@ gap gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA" gap <- gap_key %>% gs_key -# googlesheets may be able to determine the key from the browser URL -# may not work (yet) for old sheets ... open an issue if have problem +# Have a sharing link? +# Access it by URL! gap_url <- "https://docs.google.com/spreadsheets/d/1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA/" gap <- gap_url %>% gs_url +# note: registration via URL may not work for "old" sheets ``` -### Get a Google spreadsheet to practice with - -If you don't have any suitable Google Sheets lying around, or if you just want to follow along verbatim with this vignette, this bit of code will copy a sheet from the `googlesheets` Google user into your Drive. The sheet holds some of the [Gapminder data](https://github.com/jennybc/gapminder). - -```{r copy-gapminder, eval = FALSE} -gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA" -gs_copy(gs_key(gap_key), to = "Gapminder") -``` +These functions 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. -If that seems to have worked, go check that you see a sheet named Gapminder listed in your Google Sheets home screen: . You could also try `gs_ls()` again and make sure the Gapminder sheet is listed. +### Consume data -Now register your copy of the Gapminder sheet and you can follow along: +#### Ignorance is bliss -```{r register-gapminder, eval = FALSE} -gap <- gs_title("Gapminder") -gap -``` +*coming soon: a wrapper for the functions described below that just gets the data you want, while you remain blissfully ignorant of how we're doing it* -### Consume data +#### Specify the consumption method There are three ways to consume data from a worksheet within a Google spreadsheet. The order goes from fastest-but-more-limited to slowest-but-most-flexible: * `get_via_csv()`: Don't let the name scare you! Nothing is written to file during this process. The name just reflects that, under the hood, we request the data via the "exportcsv" link. For cases where `get_via_csv()` and `get_via_lf()` both work, we see that `get_via_csv()` is around __50 times faster__. Use this when your data occupies a nice rectangle in the sheet and you're willing to consume all of it. You will get a `tbl_df` back, which is basically just a `data.frame`. - * `get_via_lf()`: Gets data via the ["list feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds), which consumes data row-by-row. Like `get_via_csv()`, this is appropriate when your data occupies a nice rectangle. You will again get a `tbl_df` back, but your variable names may have been mangled (by Google, not us!). Specifically, variable names will be forcefully lowercased and all non-alpha-numeric characters will be removed. Why do we even have this function? The list feed supports some query parameters for sorting and filtering the data, which we plan to support in the near future (#17). + * `get_via_lf()`: Gets data via the ["list feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds), which consumes data row-by-row. Like `get_via_csv()`, this is appropriate when your data occupies a nice rectangle. You will again get a `tbl_df` back, but your variable names may have been mangled (by Google, not us!). Specifically, variable names will be forcefully lowercased and all non-alpha-numeric characters will be removed. Why do we even have this function? The list feed supports some query parameters for sorting and filtering the data, which we plan to support (#17). * `get_via_cf()`: Get data via the ["cell feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds), which consumes data cell-by-cell. This is appropriate when you want to consume arbitrary cells, rows, columns, and regions of the sheet. It works great for small amounts of data but can be rather slow otherwise. `get_via_cf()` returns a `tbl_df` with __one row per cell__. You can specify cell limits directly in `get_via_cf()` or use convenience wrappers `get_row()`, `get_col()` or `get_cells()` for some common special cases. See below for demos of `reshape_cf()` and `simplify_cf()` which help with post-processing. - ```{r csv-list-and-cell-feed} # Get the data for worksheet "Oceania": the super-fast csv way oceania_csv <- gap %>% get_via_csv(ws = "Oceania") @@ -203,19 +215,21 @@ foo <- gs_new("foo") foo ``` -By default, there will be an empty worksheet called "Sheet1". You can also add, rename, and delete worksheets within an existing sheet via `add_ws()`, `rename_ws()`, and `delete_ws()`. Copy an entire spreadsheet with `copy_ss()`. +By default, there will be an empty worksheet called "Sheet1". 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()`. + +*`gs_new()` and `gs_ws_new()` will soon gain the ability to populate with data upon creation (#116)* ### Edit cells -You can modify the data in sheet cells via `edit_cells()`. We'll work on 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). +You can modify the data in sheet cells via `edit_cells()`. We'll work on 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. ```{r edit-cells} foo <- foo %>% edit_cells(input = head(iris), header = TRUE, trim = TRUE) ``` -Go to [your spreadsheets home page](https://docs.google.com/spreadsheets/u/0/), find the new sheet `foo` and look at it. You should see some iris data in the first (and only) worksheet. We'll also take a look at it here, by consuming `foo` via the list feed. +Go to [your Google Sheets home screen](https://docs.google.com/spreadsheets/u/0/), find the new sheet `foo` and look at it. You should see some iris data in the first (and only) worksheet. We'll also take a look at it here, by consuming `foo` via the list feed. -Note that we always store the returned value from `edit_cells()` (and all other sheet editing functions). That's because the registration info changes whenever we edit the sheet and we re-register it inside these functions, so this idiom will help you make sequential edits and queries to the same sheet. +Note how we always store the returned value from `edit_cells()` (and all other sheet editing functions). That's because the registration info changes whenever we edit the sheet and we re-register it inside these functions, so this idiom will help you make sequential edits and queries to the same sheet. ```{r consume-edited-cells} foo %>% get_via_lf() @@ -246,7 +260,7 @@ file.remove("iris.csv") Now we'll upload a multi-sheet Excel workbook. Slowly. ```{r new-sheet-from-xlsx} -gap_xlsx <- gs_upload("tests/testthat/mini-gap.xlsx") +gap_xlsx <- gs_upload(system.file("mini-gap.xlsx", package = "googlesheets")) gap_xlsx gap_xlsx %>% get_via_lf(ws = "Oceania") ``` @@ -263,8 +277,8 @@ gs_delete(gap_xlsx) You can download a Google Sheet as a csv, pdf, or xlsx file. Downloading the spreadsheet as a csv file will export the first worksheet (default) unless another worksheet is specified. ```{r export-sheet-as-csv} -gs_download(gs_title("Gapminder"), ws = "Africa", - to = "~/tmp/gapminder-africa.csv") +gs_title("Gapminder") %>% + gs_download(ws = "Africa", to = "~/tmp/gapminder-africa.csv") ## is it there? yes! read.csv("~/tmp/gapminder-africa.csv") %>% head() ``` @@ -272,7 +286,8 @@ read.csv("~/tmp/gapminder-africa.csv") %>% head() Download the entire spreadsheet as an Excel workbook. ```{r export-sheet-as-xlsx} -gs_download(gs_title("Gapminder"), to = "~/tmp/gapminder.xlsx") +gs_title("Gapminder") %>% + gs_download(to = "~/tmp/gapminder.xlsx") ``` Go check it out in Excel, if you wish! diff --git a/README.md b/README.md index 64ea683..751bd97 100644 --- a/README.md +++ b/README.md @@ -43,31 +43,41 @@ What other ideas do you have? devtools::install_github("jennybc/googlesheets") ``` +*We plan to submit to CRAN in late May or early June 2015, so feedback on functionality and usability is especially valuable to us now!* + ### Take a look at the vignette -This README is arguably as or more useful as the vignette and both are still under development. But feel free to [check out the current state of the vignette](http://htmlpreview.github.io/?https://raw.githubusercontent.com/jennybc/googlesheets/master/vignettes/basic-usage.html). +No, actually, **don't**. This README is much more current than the vignette, though that will have to change soon! + +If you insist, [check out the current state of the vignette](http://htmlpreview.github.io/?https://raw.githubusercontent.com/jennybc/googlesheets/master/vignettes/basic-usage.html). ### Load googlesheets -`googlesheets` is designed for use with the `%>%` pipe operator and, to a lesser extent, the data-wrangling mentality of `dplyr`. The examples here use both, but we'll soon develop a vignette that shows usage with plain vanilla R. `googlesheets` uses `dplyr` internally but does not require the user to do so. +`googlesheets` is designed for use with the `%>%` pipe operator and, to a lesser extent, the data-wrangling mentality of [`dplyr`](http://cran.r-project.org/web/packages/dplyr/index.html). This README uses both, but the examples in the help files emphasize usage with plain vanilla R, if that's how you roll. `googlesheets` uses `dplyr` internally but does not require the user to do so. You can make the `%>%` pipe operator availble in your own work by loading [`dplyr`](http://cran.r-project.org/web/packages/dplyr/index.html) or [`magrittr`](http://cran.r-project.org/web/packages/magrittr/index.html). ``` r library("googlesheets") suppressMessages(library("dplyr")) ``` +### Function naming convention + +*implementation not yet 100% complete ... but we'll get there soon* + +All functions start with `gs_`, which plays nicely with tab completion in RStudio, for example. If the function has something to do with worksheets or tabs within a spreadsheet, it will start with `gs_ws_`. + ### 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, especially if you have clicked on a link shared by the owner. 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 visited the sheet in the browser. Expect a prompt to authenticate yourself in the browser at this point (more below re: authentication). ``` r (my_sheets <- gs_ls()) #> Source: local data frame [32 x 10] #> #> sheet_title author perm version updated -#> 1 Ari's Anchor Text Scrap… anahmani r old 2015-05-08 06:05:08 -#> 2 EasyTweetSheet - Shared m.hawksey r new 2015-05-08 05:35:23 -#> 3 #rhizo15 #tw m.hawksey r new 2015-05-08 06:05:39 +#> 1 Ari's Anchor Text Scrap… anahmani r old 2015-05-08 18:24:16 +#> 2 #rhizo15 #tw m.hawksey r new 2015-05-08 20:00:01 +#> 3 EasyTweetSheet - Shared m.hawksey r new 2015-05-08 21:58:48 #> 4 gas_mileage woo.kara r new 2015-05-04 01:14:13 #> 5 #TalkPay Tweets iskaldur r new 2015-05-02 06:25:14 #> 6 test-gs-old-sheet2 gspreadr rw old 2015-04-30 23:33:48 @@ -82,29 +92,41 @@ The `gs_ls()` function returns the sheets you would see in your Google Sheets ho my_sheets %>% glimpse() #> Observations: 32 #> Variables: -#> $ sheet_title (chr) "Ari's Anchor Text Scraper", "EasyTweetSheet - Sha... +#> $ sheet_title (chr) "Ari's Anchor Text Scraper", "#rhizo15 #tw", "Easy... #> $ author (chr) "anahmani", "m.hawksey", "m.hawksey", "woo.kara", ... #> $ perm (chr) "r", "r", "r", "r", "r", "rw", "r", "rw", "rw", "r... #> $ version (chr) "old", "new", "new", "new", "new", "old", "new", "... -#> $ updated (time) 2015-05-08 06:05:08, 2015-05-08 05:35:23, 2015-05... -#> $ sheet_key (chr) "tQKSYVRwBXssUfYEaMdt-aw", "14mAbIi1UyZtJTDuIa7iMb... +#> $ updated (time) 2015-05-08 18:24:16, 2015-05-08 20:00:01, 2015-05... +#> $ sheet_key (chr) "tQKSYVRwBXssUfYEaMdt-aw", "1oBQNnsMY8Qkuui6BAE8Tn... #> $ ws_feed (chr) "https://spreadsheets.google.com/feeds/worksheets/... #> $ alternate (chr) "https://spreadsheets.google.com/ccc?key=0Av8m6X4c... #> $ self (chr) "https://spreadsheets.google.com/feeds/spreadsheet... #> $ alt_key (chr) "0Av8m6X4cYe9hdFFLU1lWUndCWHNzVWZZRWFNZHQtYXc", NA... ``` +### Get a Google spreadsheet to practice with + +If you don't have any suitable Google Sheets lying around, or if you just want to follow along verbatim with this vignette, this bit of code will copy a sheet from the `googlesheets` Google user into your Drive. The sheet holds some of the [Gapminder data](https://github.com/jennybc/gapminder). + +``` r +gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA" +gs_copy(gs_key(gap_key), to = "Gapminder") +``` + +If that seems to have worked, go check that you see a sheet named "Gapminder" listed in your Google Sheets home screen: . You could also run `gs_ls()` again and make sure the Gapminder sheet is listed. + ### Register a spreadsheet -If you plan to consume data from a sheet or edit it, you must first register it. Basically this is where `googlesheets` makes a note of important info about the sheet that's needed to access via the Sheets API. Once registered, you can print the result to get some basic info about the sheet. +If you plan to consume data from a sheet or edit it, you must first **register** it. This is how `googlesheets` records important info about the sheet that is required downstream by the Google Sheets or Google Drive APIs. Once registered, you can print the result to get some basic info about the sheet. + +`googlesheets` provides several registration functions. Specifying the sheet by title? Use `gs_title()`. By key? Use `gs_key()`. You get the idea. ``` r -# Hey let's look at the Gapminder data gap <- gs_title("Gapminder") #> Sheet successfully identifed: "Gapminder" gap #> Spreadsheet title: Gapminder -#> Date of googlesheets registration: 2015-05-08 06:08:53 GMT +#> Date of googlesheets registration: 2015-05-08 22:14:25 GMT #> Date of last spreadsheet update: 2015-03-23 20:34:08 GMT #> visibility: private #> permissions: rw @@ -127,8 +149,8 @@ gap <- gap_key %>% gs_key #> Authentication will be used. #> Sheet successfully identifed: "Gapminder" -# googlesheets may be able to determine the key from the browser URL -# may not work (yet) for old sheets ... open an issue if have problem +# Have a sharing link? +# Access it by URL! gap_url <- "https://docs.google.com/spreadsheets/d/1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA/" gap <- gap_url %>% gs_url #> Authentication will be used. @@ -137,32 +159,23 @@ gap <- gap_url %>% gs_url #> Putative key: 1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA #> Authentication will be used. #> Sheet successfully identifed: "Gapminder" +# note: registration via URL may not work for "old" sheets ``` -### Get a Google spreadsheet to practice with +These functions 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. -If you don't have any suitable Google Sheets lying around, or if you just want to follow along verbatim with this vignette, this bit of code will copy a sheet from the `googlesheets` Google user into your Drive. The sheet holds some of the [Gapminder data](https://github.com/jennybc/gapminder). - -``` r -gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA" -gs_copy(gs_key(gap_key), to = "Gapminder") -``` - -If that seems to have worked, go check that you see a sheet named Gapminder listed in your Google Sheets home screen: . You could also try `gs_ls()` again and make sure the Gapminder sheet is listed. +### Consume data -Now register your copy of the Gapminder sheet and you can follow along: +#### Ignorance is bliss -``` r -gap <- gs_title("Gapminder") -gap -``` +*coming soon: a wrapper for the functions described below that just gets the data you want, while you remain blissfully ignorant of how we're doing it* -### Consume data +#### Specify the consumption method There are three ways to consume data from a worksheet within a Google spreadsheet. The order goes from fastest-but-more-limited to slowest-but-most-flexible: - `get_via_csv()`: Don't let the name scare you! Nothing is written to file during this process. The name just reflects that, under the hood, we request the data via the "exportcsv" link. For cases where `get_via_csv()` and `get_via_lf()` both work, we see that `get_via_csv()` is around **50 times faster**. Use this when your data occupies a nice rectangle in the sheet and you're willing to consume all of it. You will get a `tbl_df` back, which is basically just a `data.frame`. -- `get_via_lf()`: Gets data via the ["list feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds), which consumes data row-by-row. Like `get_via_csv()`, this is appropriate when your data occupies a nice rectangle. You will again get a `tbl_df` back, but your variable names may have been mangled (by Google, not us!). Specifically, variable names will be forcefully lowercased and all non-alpha-numeric characters will be removed. Why do we even have this function? The list feed supports some query parameters for sorting and filtering the data, which we plan to support in the near future (\#17). +- `get_via_lf()`: Gets data via the ["list feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_list-based_feeds), which consumes data row-by-row. Like `get_via_csv()`, this is appropriate when your data occupies a nice rectangle. You will again get a `tbl_df` back, but your variable names may have been mangled (by Google, not us!). Specifically, variable names will be forcefully lowercased and all non-alpha-numeric characters will be removed. Why do we even have this function? The list feed supports some query parameters for sorting and filtering the data, which we plan to support (\#17). - `get_via_cf()`: Get data via the ["cell feed"](https://developers.google.com/google-apps/spreadsheets/#working_with_cell-based_feeds), which consumes data cell-by-cell. This is appropriate when you want to consume arbitrary cells, rows, columns, and regions of the sheet. It works great for small amounts of data but can be rather slow otherwise. `get_via_cf()` returns a `tbl_df` with **one row per cell**. You can specify cell limits directly in `get_via_cf()` or use convenience wrappers `get_row()`, `get_col()` or `get_cells()` for some common special cases. See below for demos of `reshape_cf()` and `simplify_cf()` which help with post-processing. ``` r @@ -376,8 +389,8 @@ foo <- gs_new("foo") #> Sheet "foo" created in Google Drive. foo #> Spreadsheet title: foo -#> Date of googlesheets registration: 2015-05-08 06:08:59 GMT -#> Date of last spreadsheet update: 2015-05-08 06:08:58 GMT +#> Date of googlesheets registration: 2015-05-08 22:14:32 GMT +#> Date of last spreadsheet update: 2015-05-08 22:14:31 GMT #> visibility: private #> permissions: rw #> version: new @@ -386,26 +399,31 @@ foo #> (Title): (Nominal worksheet extent as rows x columns) #> Sheet1: 1000 x 26 #> -#> Key: 1x9_DkE1YckatCBIDjDxq9lBdnfpowAIkwgLLQZ23AMA +#> Key: 1FbvMz7bUiSKRuQjKU7SjmXpWGUYUA3djybHTsXZ25Yg ``` -By default, there will be an empty worksheet called "Sheet1". You can also add, rename, and delete worksheets within an existing sheet via `add_ws()`, `rename_ws()`, and `delete_ws()`. Copy an entire spreadsheet with `copy_ss()`. +By default, there will be an empty worksheet called "Sheet1". 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()`. + +*`gs_new()` and `gs_ws_new()` will soon gain the ability to populate with data upon creation (\#116)* ### Edit cells -You can modify the data in sheet cells via `edit_cells()`. We'll work on 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). +You can modify the data in sheet cells via `edit_cells()`. We'll work on 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. ``` r foo <- foo %>% edit_cells(input = head(iris), header = TRUE, trim = TRUE) #> Range affected by the update: "A1:E7" #> Worksheet "Sheet1" successfully updated with 35 new value(s). #> Accessing worksheet titled "Sheet1" +#> Authentication will be used. +#> Sheet successfully identifed: "foo" +#> Accessing worksheet titled "Sheet1" #> Worksheet "Sheet1" dimensions changed to 7 x 5. ``` -Go to [your spreadsheets home page](https://docs.google.com/spreadsheets/u/0/), find the new sheet `foo` and look at it. You should see some iris data in the first (and only) worksheet. We'll also take a look at it here, by consuming `foo` via the list feed. +Go to [your Google Sheets home screen](https://docs.google.com/spreadsheets/u/0/), find the new sheet `foo` and look at it. You should see some iris data in the first (and only) worksheet. We'll also take a look at it here, by consuming `foo` via the list feed. -Note that we always store the returned value from `edit_cells()` (and all other sheet editing functions). That's because the registration info changes whenever we edit the sheet and we re-register it inside these functions, so this idiom will help you make sequential edits and queries to the same sheet. +Note how we always store the returned value from `edit_cells()` (and all other sheet editing functions). That's because the registration info changes whenever we edit the sheet and we re-register it inside these functions, so this idiom will help you make sequential edits and queries to the same sheet. ``` r foo %>% get_via_lf() @@ -442,8 +460,8 @@ iris_ss <- gs_upload("iris.csv") #> "iris.csv" uploaded to Google Drive and converted to a Google Sheet named "iris" iris_ss #> Spreadsheet title: iris -#> Date of googlesheets registration: 2015-05-08 06:09:11 GMT -#> Date of last spreadsheet update: 2015-05-08 06:09:09 GMT +#> Date of googlesheets registration: 2015-05-08 22:14:45 GMT +#> Date of last spreadsheet update: 2015-05-08 22:14:43 GMT #> visibility: private #> permissions: rw #> version: new @@ -452,7 +470,7 @@ iris_ss #> (Title): (Nominal worksheet extent as rows x columns) #> iris: 6 x 5 #> -#> Key: 1oZZ2_G-dL8QjePP48l7ap5JHGFau44JLI0HjJLrqLjU +#> Key: 1hVwexynuPsTxVDbTk6-aB6PqCwbVV9zyxt3WfwRrfU4 iris_ss %>% get_via_lf() #> Accessing worksheet titled "iris" #> Source: local data frame [5 x 5] @@ -470,12 +488,12 @@ file.remove("iris.csv") Now we'll upload a multi-sheet Excel workbook. Slowly. ``` r -gap_xlsx <- gs_upload("tests/testthat/mini-gap.xlsx") +gap_xlsx <- gs_upload(system.file("mini-gap.xlsx", package = "googlesheets")) #> "mini-gap.xlsx" uploaded to Google Drive and converted to a Google Sheet named "mini-gap" gap_xlsx #> Spreadsheet title: mini-gap -#> Date of googlesheets registration: 2015-05-08 06:09:15 GMT -#> Date of last spreadsheet update: 2015-05-08 06:09:14 GMT +#> Date of googlesheets registration: 2015-05-08 22:14:50 GMT +#> Date of last spreadsheet update: 2015-05-08 22:14:48 GMT #> visibility: private #> permissions: rw #> version: new @@ -488,7 +506,7 @@ gap_xlsx #> Europe: 20 x 6 #> Oceania: 20 x 6 #> -#> Key: 1hQ2DqoOaW_clf-Xqw2qajJz1Ag19Ikhmy5B7T8GwE8g +#> Key: 1dZMbPWsEVJlfu1a0SoryJoWGRDfMXj-uLDGwRjRGgmI gap_xlsx %>% get_via_lf(ws = "Oceania") #> Accessing worksheet titled "Oceania" #> Source: local data frame [5 x 6] @@ -515,8 +533,8 @@ gs_delete(gap_xlsx) You can download a Google Sheet as a csv, pdf, or xlsx file. Downloading the spreadsheet as a csv file will export the first worksheet (default) unless another worksheet is specified. ``` r -gs_download(gs_title("Gapminder"), ws = "Africa", - to = "~/tmp/gapminder-africa.csv") +gs_title("Gapminder") %>% + gs_download(ws = "Africa", to = "~/tmp/gapminder-africa.csv") #> Sheet successfully identifed: "Gapminder" #> Accessing worksheet titled "Africa" #> Sheet successfully downloaded: /Users/jenny/tmp/gapminder-africa.csv @@ -534,7 +552,8 @@ read.csv("~/tmp/gapminder-africa.csv") %>% head() Download the entire spreadsheet as an Excel workbook. ``` r -gs_download(gs_title("Gapminder"), to = "~/tmp/gapminder.xlsx") +gs_title("Gapminder") %>% + gs_download(to = "~/tmp/gapminder.xlsx") #> Sheet successfully identifed: "Gapminder" #> Sheet successfully downloaded: /Users/jenny/tmp/gapminder.xlsx ``` diff --git a/vignettes/basic-usage.R b/vignettes/basic-usage.R index f24f3ed..9c61caa 100644 --- a/vignettes/basic-usage.R +++ b/vignettes/basic-usage.R @@ -29,13 +29,7 @@ gs_vecdel("hi I am new here", verbose = FALSE) ## ----list-sheets--------------------------------------------------------- my_sheets <- gs_ls() - -## ----view-my-sheets, echo = FALSE---------------------------------------- -my_sheets %>% - head %>% - mutate(sheet_title = substr(sheet_title, 1, 10), - sheet_key = sheet_key %>% substr(1, 7) %>% stringr::str_c("...")) %>% - select(-ws_feed) +my_sheets ## ------------------------------------------------------------------------ gap <- gs_title("Gapminder") diff --git a/vignettes/basic-usage.Rmd b/vignettes/basic-usage.Rmd index 3f26efa..65e8cda 100644 --- a/vignettes/basic-usage.Rmd +++ b/vignettes/basic-usage.Rmd @@ -12,7 +12,7 @@ vignette: > \usepackage[utf8]{inputenc} --- -__NOTE__: The vignette is still under development. Stuff here is not written in stone. The [README](https://github.com/jennybc/googlesheets) on GitHub has gotten alot more love recently, so you might want to read that instead or in addition to this (2015-03-23). +__NOTE__: The vignette is still under development. Stuff here is not written in stone. The [README](https://github.com/jennybc/googlesheets) on GitHub has gotten __alot more love recently__, so you should read that instead or in addition to this (2015-05-08). Seriously, we've only been making sure this thing compiles, but not updating the text. ```{r load package} library(googlesheets) @@ -25,9 +25,9 @@ This vignette shows the basic functionality of `googlesheets`. In order to access spreadsheets that are not "published to the web" and in order to access __any__ spreadsheets by title (vs key), you need to authenticate with Google. Many `googlesheets` functions require authentication and, if necessary, will simply trigger the interactive process we describe here. -The `authorize()` function uses OAuth2 for authentication, but don't worry if you don't know what that means. The first time, you will be kicked into a web browser. You'll be asked to login to your Google account and give `googlesheets` permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named `.httr-oath` in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the `httr` package to manage this. +The `gs_auth()` function uses OAuth2 for authentication, but don't worry if you don't know what that means. The first time, you will be kicked into a web browser. You'll be asked to login to your Google account and give `googlesheets` permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named `.httr-oath` in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the `httr` package to manage this. -If you want to switch to a different Google account, run `authorize(new_user = TRUE)`, as this will delete the previously stored token and get a new one for the new account. +If you want to switch to a different Google account, run `gs_auth(new_user = TRUE)`, as this will delete the previously stored token and get a new one for the new account. *In a hidden chunk, we are logging into Google as a user associated with this package, so we can work with some Google spreadsheets later in this vignette.* @@ -70,25 +70,16 @@ As an authenticated user, you can get a (partial) listing of accessible sheets. ```{r list-sheets} my_sheets <- gs_ls() +my_sheets ``` -Explore the `my_sheets` object. Here's a look at the top of ours, where we've truncated the variables `sheet_title` and `sheet_key` and suppressed the variable `ws_id` for readability. - -```{r view-my-sheets, echo = FALSE} -my_sheets %>% - head %>% - mutate(sheet_title = substr(sheet_title, 1, 10), - sheet_key = sheet_key %>% substr(1, 7) %>% stringr::str_c("...")) %>% - select(-ws_feed) -``` - -This provides a nice overview of the spreadsheets you can access and is useful for looking up the __key__ of a spreadsheet (see below). +This provides a nice overview of the spreadsheets you can access. # Register a spreadsheet -Before you can access a spreadsheet, you must first __register__ it. This returns an object that is of little interest to the user, but is needed by various `googlesheets` functions in order to retrieve or edit spreadsheet data. +Before you can access a spreadsheet, you must first __register__ it. This returns a `googlesheets` object that is needed by downstream functions in order to retrieve or edit spreadsheet data. -Let's register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We can use `str()` to get an overview of the spreadsheet. +Let's register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We have a nice `print` method for these objects, so print to screen for some basic info. ```{r} gap <- gs_title("Gapminder") @@ -101,7 +92,7 @@ Besides using the spreadsheet title, you can also specify a spreadsheet in three * By URL: copy and paste the URL in your browser while visiting the spreadsheet. * By the "worksheets feed": under the hood, this is how `googlesheets` actually gets spreadsheet information from the API. Unlikely to be relevant to a regular user. -Here's an example of using the sheet title to retrieve the key, then registering the sheet by key. While registration by title is handy for interactive use, registration by key is preferred for scripts. +Here's an example of registering a sheet via key. While registration by title is handy for interactive use, registration by key might be preferred when programming. ```{r} (gap_key <- my_sheets$sheet_key[my_sheets$sheet_title == "Gapminder"]) @@ -113,8 +104,9 @@ ss2 Spreadsheet data is parcelled out into __worksheets__. To consume data from a Google spreadsheet, you'll need to specify a registered spreadsheet and, within that, a worksheet. Specify the worksheet either by name or positive integer index. -There are two ways to consume data. +There are three ways to consume data. + * *The csv way ... bring this over from README* * The "list feed": only suitable for well-behaved tabular data. Think: data that looks like an R data.frame * The "cell feed": for everything else. Of course, you can get well-behaved tabular data with the cell feed but it's up to 3x slower and will require post-processing (reshaping and coercion). @@ -161,7 +153,7 @@ There are two basic modes of consuming data stored in a worksheet (quotes taken *Rework this for the new era.* -Under the hood, `gspread` functions must access a spreadsheet with either public or private __visiblity__. Visibility determines whether or not authorization will be used for a request. +Under the hood, `googlesheets` functions must access a spreadsheet with either public or private __visiblity__. Visibility determines whether or not authorization will be used for a request. No authorization is used when visibility is set to "public", which will only work for spreadsheets that have been "Published to the Web". Note that requests with visibility set to "public" __will not work__ for spreadsheets that are made "Public on the web" from the "Visibility options" portion of the sharing dialog of a Google Sheets file. In summary, "Published to the web" and "Public on the web" are __different__ ways to share a spreadsheet. @@ -183,7 +175,7 @@ To access public spreadsheets, you will either need the key of the spreadsheet ( ### Add or delete spreadsheet -To add a spreadsheet to your Google Drive, use `gs_new()` and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled "Sheet1" by default. Recall we demonstrate the use of `copy_ss()` at the start of this vignette, which is another common way to get a new sheet. +To add a spreadsheet to your Google Drive, use `gs_new()` and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled "Sheet1" by default. Recall we demonstrate the use of `gs_copy()` at the start of this vignette, which is another common way to get a new sheet. or delete or `gs_delete()` @@ -204,7 +196,7 @@ gs_ls() %>% filter(sheet_title == "hi I am new here") ### Add, delete, or rename a worksheet -To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local spreadsheet object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to `x` after adding the worksheet. This is because adding a worksheet changes the information associate with a registered sheet and, within editing function like `add_ws()`, we re-register the sheet and return the current sheet info. +To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local `googlesheet` object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to `x` after adding the worksheet. This is because adding a worksheet changes the information associated with a registered sheet and, within editing functions like `gs_ws_new()`, we re-register the sheet and return the current sheet info. ```{r new-sheet-new-ws-delete-ws} gs_new("hi I am new here") diff --git a/vignettes/basic-usage.html b/vignettes/basic-usage.html index 3726965..a60f433 100644 --- a/vignettes/basic-usage.html +++ b/vignettes/basic-usage.html @@ -79,15 +79,15 @@

2015-05-08

-

NOTE: The vignette is still under development. Stuff here is not written in stone. The README on GitHub has gotten alot more love recently, so you might want to read that instead or in addition to this (2015-03-23).

+

NOTE: The vignette is still under development. Stuff here is not written in stone. The README on GitHub has gotten alot more love recently, so you should read that instead or in addition to this (2015-05-08). Seriously, we’ve only been making sure this thing compiles, but not updating the text.

library(googlesheets)
 suppressMessages(library(dplyr))

This vignette shows the basic functionality of googlesheets.

User Authentication

In order to access spreadsheets that are not “published to the web” and in order to access any spreadsheets by title (vs key), you need to authenticate with Google. Many googlesheets functions require authentication and, if necessary, will simply trigger the interactive process we describe here.

-

The authorize() function uses OAuth2 for authentication, but don’t worry if you don’t know what that means. The first time, you will be kicked into a web browser. You’ll be asked to login to your Google account and give googlesheets permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named .httr-oath in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the httr package to manage this.

-

If you want to switch to a different Google account, run authorize(new_user = TRUE), as this will delete the previously stored token and get a new one for the new account.

+

The gs_auth() function uses OAuth2 for authentication, but don’t worry if you don’t know what that means. The first time, you will be kicked into a web browser. You’ll be asked to login to your Google account and give googlesheets permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named .httr-oath in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the httr package to manage this.

+

If you want to switch to a different Google account, run gs_auth(new_user = TRUE), as this will delete the previously stored token and get a new one for the new account.

In a hidden chunk, we are logging into Google as a user associated with this package, so we can work with some Google spreadsheets later in this vignette.

@@ -99,29 +99,35 @@

Get a Google spreadsheet to practice with

List your spreadsheets

As an authenticated user, you can get a (partial) listing of accessible sheets. If you have not yet authenticated, you will be prompted to do so. If it’s been a while since you authenticated, you’ll see a message about refreshing a stale OAuth token.

-
my_sheets <- gs_ls()
-

Explore the my_sheets object. Here’s a look at the top of ours, where we’ve truncated the variables sheet_title and sheet_key and suppressed the variable ws_id for readability.

-
## Source: local data frame [6 x 9]
+
my_sheets <- gs_ls()
+my_sheets
+
## Source: local data frame [33 x 10]
 ## 
-##   sheet_title    author perm version             updated  sheet_key
-## 1  Ari's Anch  anahmani    r     old 2015-05-08 18:24:16 tQKSYVR...
-## 2  #rhizo15 # m.hawksey    r     new 2015-05-08 18:51:36 1oBQNns...
-## 3  EasyTweetS m.hawksey    r     new 2015-05-08 18:28:47 14mAbIi...
-## 4  gas_mileag  woo.kara    r     new 2015-05-04 01:14:13 1WH65aJ...
-## 5  #TalkPay T  iskaldur    r     new 2015-05-02 06:25:14 1IK1an_...
-## 6  test-gs-ol  gspreadr   rw     old 2015-04-30 23:33:48 t0lmRSk...
-## Variables not shown: alternate (chr), self (chr), alt_key (chr)
-

This provides a nice overview of the spreadsheets you can access and is useful for looking up the key of a spreadsheet (see below).

+## sheet_title author perm version updated +## 1 foo gspreadr rw new 2015-05-08 22:14:30 +## 2 Ari's Anchor Text Scrap… anahmani r old 2015-05-08 18:24:16 +## 3 #rhizo15 #tw m.hawksey r new 2015-05-08 20:00:01 +## 4 EasyTweetSheet - Shared m.hawksey r new 2015-05-08 21:58:48 +## 5 gas_mileage woo.kara r new 2015-05-04 01:14:13 +## 6 #TalkPay Tweets iskaldur r new 2015-05-02 06:25:14 +## 7 test-gs-old-sheet2 gspreadr rw old 2015-04-30 23:33:48 +## 8 test-gs-mini-gapminder rpackagetest r new 2015-04-25 18:25:43 +## 9 test-gs-iris-private gspreadr rw new 2015-04-25 15:18:05 +## 10 1F0iNuYW4v_oG69s7c5Nzdo… gspreadr rw new 2015-04-25 02:32:24 +## .. ... ... ... ... ... +## Variables not shown: sheet_key (chr), ws_feed (chr), alternate (chr), self +## (chr), alt_key (chr)
+

This provides a nice overview of the spreadsheets you can access.

Register a spreadsheet

-

Before you can access a spreadsheet, you must first register it. This returns an object that is of little interest to the user, but is needed by various googlesheets functions in order to retrieve or edit spreadsheet data.

-

Let’s register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We can use str() to get an overview of the spreadsheet.

+

Before you can access a spreadsheet, you must first register it. This returns a googlesheets object that is needed by downstream functions in order to retrieve or edit spreadsheet data.

+

Let’s register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We have a nice print method for these objects, so print to screen for some basic info.

gap <- gs_title("Gapminder")
## Sheet successfully identifed: "Gapminder"
gap
##                   Spreadsheet title: Gapminder
-##   Date of googlesheets registration: 2015-05-08 18:52:29 GMT
+##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
 ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
 ##                          visibility: private
 ##                         permissions: rw
@@ -142,7 +148,7 @@ 

Register a spreadsheet

  • By URL: copy and paste the URL in your browser while visiting the spreadsheet.
  • By the “worksheets feed”: under the hood, this is how googlesheets actually gets spreadsheet information from the API. Unlikely to be relevant to a regular user.
  • -

    Here’s an example of using the sheet title to retrieve the key, then registering the sheet by key. While registration by title is handy for interactive use, registration by key is preferred for scripts.

    +

    Here’s an example of registering a sheet via key. While registration by title is handy for interactive use, registration by key might be preferred when programming.

    (gap_key <- my_sheets$sheet_key[my_sheets$sheet_title == "Gapminder"])
    ## [1] "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
    ss2 <- gs_key(gap_key)
    @@ -150,7 +156,7 @@

    Register a spreadsheet

    ## Sheet successfully identifed: "Gapminder"
    ss2
    ##                   Spreadsheet title: Gapminder
    -##   Date of googlesheets registration: 2015-05-08 18:52:30 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
     ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
     ##                          visibility: private
     ##                         permissions: rw
    @@ -169,15 +175,16 @@ 

    Register a spreadsheet

    Consuming data from a worksheet

    Spreadsheet data is parcelled out into worksheets. To consume data from a Google spreadsheet, you’ll need to specify a registered spreadsheet and, within that, a worksheet. Specify the worksheet either by name or positive integer index.

    -

    There are two ways to consume data.

    +

    There are three ways to consume data.

      +
    • The csv way … bring this over from README
    • The “list feed”: only suitable for well-behaved tabular data. Think: data that looks like an R data.frame
    • The “cell feed”: for everything else. Of course, you can get well-behaved tabular data with the cell feed but it’s up to 3x slower and will require post-processing (reshaping and coercion).

    Example of getting nice tabular data from the “list feed”:

    gap
    ##                   Spreadsheet title: Gapminder
    -##   Date of googlesheets registration: 2015-05-08 18:52:29 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
     ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
     ##                          visibility: private
     ##                         permissions: rw
    @@ -285,7 +292,7 @@ 

    Consuming data from a worksheet

    Visibility stuff

    Rework this for the new era.

    -

    Under the hood, gspread functions must access a spreadsheet with either public or private visiblity. Visibility determines whether or not authorization will be used for a request.

    +

    Under the hood, googlesheets functions must access a spreadsheet with either public or private visiblity. Visibility determines whether or not authorization will be used for a request.

    No authorization is used when visibility is set to “public”, which will only work for spreadsheets that have been “Published to the Web”. Note that requests with visibility set to “public” will not work for spreadsheets that are made “Public on the web” from the “Visibility options” portion of the sharing dialog of a Google Sheets file. In summary, “Published to the web” and “Public on the web” are different ways to share a spreadsheet.

    Authorization is used when visibility is set to “private”.

    @@ -304,7 +311,7 @@

    Add, delete, rename spreadsheets and worksheets

    needs updating; lots of this already in README

    Add or delete spreadsheet

    -

    To add a spreadsheet to your Google Drive, use gs_new() and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled “Sheet1” by default. Recall we demonstrate the use of copy_ss() at the start of this vignette, which is another common way to get a new sheet.

    +

    To add a spreadsheet to your Google Drive, use gs_new() and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled “Sheet1” by default. Recall we demonstrate the use of gs_copy() at the start of this vignette, which is another common way to get a new sheet.

    or delete or gs_delete()

    # Create a new empty spreadsheet by title
     gs_new("hi I am new here")
    @@ -313,7 +320,7 @@

    Add or delete spreadsheet

    ## Source: local data frame [1 x 10]
     ## 
     ##        sheet_title   author perm version             updated
    -## 1 hi I am new here gspreadr   rw     new 2015-05-08 18:52:31
    +## 1 hi I am new here gspreadr   rw     new 2015-05-08 22:14:39
     ## Variables not shown: sheet_key (chr), ws_feed (chr), alternate (chr), self
     ##   (chr), alt_key (chr)

    Delete a spreadsheet with gs_delete(). This function operates on a registered googlesheet, so enclose your sheet identifying information in a suitable function. Here we specify (and delete) the above sheet by title, then confirm it is no longer in our sheet listing.

    @@ -330,15 +337,15 @@

    Add or delete spreadsheet

    Add, delete, or rename a worksheet

    -

    To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local spreadsheet object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to x after adding the worksheet. This is because adding a worksheet changes the information associate with a registered sheet and, within editing function like add_ws(), we re-register the sheet and return the current sheet info.

    +

    To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local googlesheet object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to x after adding the worksheet. This is because adding a worksheet changes the information associated with a registered sheet and, within editing functions like gs_ws_new(), we re-register the sheet and return the current sheet info.

    gs_new("hi I am new here")
    ## Sheet "hi I am new here" created in Google Drive.
    x <- gs_title("hi I am new here")
    ## Sheet successfully identifed: "hi I am new here"
    x
    ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:38 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:36 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:49 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:46 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -347,13 +354,13 @@ 

    Add, delete, or rename a worksheet

    ## (Title): (Nominal worksheet extent as rows x columns) ## Sheet1: 1000 x 26 ## -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM
    x <- gs_ws_new(x, ws_title = "foo", nrow = 10, ncol = 10)
    ## Worksheet "foo" added to sheet "hi I am new here".
    x
    ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:39 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:38 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:49 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:49 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -363,7 +370,7 @@ 

    Add, delete, or rename a worksheet

    ## Sheet1: 1000 x 26 ## foo: 10 x 10 ## -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM
    gs_ws_delete(x, ws = "foo")
    ## Accessing worksheet titled "foo"
     ## Worksheet "foo" deleted from sheet "hi I am new here".
    @@ -371,8 +378,8 @@

    Add, delete, or rename a worksheet

    ## Sheet successfully identifed: "hi I am new here"
    x
    ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:40 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:39 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:51 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:50 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -381,7 +388,7 @@ 

    Add, delete, or rename a worksheet

    ## (Title): (Nominal worksheet extent as rows x columns) ## Sheet1: 1000 x 26 ## -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM

    To rename a worksheet, pass in the spreadsheet object, the worksheet’s current name and the new name you want it to be.

    gs_ws_rename(x, "Sheet1", "First Sheet")
    ## Accessing worksheet titled "Sheet1"
    diff --git a/vignettes/basic-usage.md b/vignettes/basic-usage.md
    index 0ad4016..b598a6b 100644
    --- a/vignettes/basic-usage.md
    +++ b/vignettes/basic-usage.md
    @@ -2,7 +2,7 @@
     Joanna Zhao, Jenny Bryan  
     `r Sys.Date()`  
     
    -__NOTE__: The vignette is still under development. Stuff here is not written in stone. The [README](https://github.com/jennybc/googlesheets) on GitHub has gotten alot more love recently, so you might want to read that instead or in addition to this (2015-03-23).
    +__NOTE__: The vignette is still under development. Stuff here is not written in stone. The [README](https://github.com/jennybc/googlesheets) on GitHub has gotten __alot more love recently__, so you should read that instead or in addition to this (2015-05-08). Seriously, we've only been making sure this thing compiles, but not updating the text.
     
     
     ```r
    @@ -16,9 +16,9 @@ This vignette shows the basic functionality of `googlesheets`.
     
     In order to access spreadsheets that are not "published to the web" and in order to access __any__ spreadsheets by title (vs key), you need to authenticate with Google. Many `googlesheets` functions require authentication and, if necessary, will simply trigger the interactive process we describe here.
     
    -The `authorize()` function uses OAuth2 for authentication, but don't worry if you don't know what that means. The first time, you will be kicked into a web browser. You'll be asked to login to your Google account and give `googlesheets` permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named `.httr-oath` in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the `httr` package to manage this.
    +The `gs_auth()` function uses OAuth2 for authentication, but don't worry if you don't know what that means. The first time, you will be kicked into a web browser. You'll be asked to login to your Google account and give `googlesheets` permission to access Sheets and Google Drive. Successful login will lead to the creation of an access token, which will automatically be stored in a file named `.httr-oath` in current working directory. These tokens are perishable and, for the most part, they will be refreshed automatically when they go stale. Under the hood, we use the `httr` package to manage this.
     
    -If you want to switch to a different Google account, run `authorize(new_user = TRUE)`, as this will delete the previously stored token and get a new one for the new account.
    +If you want to switch to a different Google account, run `gs_auth(new_user = TRUE)`, as this will delete the previously stored token and get a new one for the new account.
     
     *In a hidden chunk, we are logging into Google as a user associated with this package, so we can work with some Google spreadsheets later in this vignette.*
     
    @@ -44,31 +44,35 @@ As an authenticated user, you can get a (partial) listing of accessible sheets.
     
     ```r
     my_sheets <- gs_ls()
    +my_sheets
     ```
     
    -Explore the `my_sheets` object. Here's a look at the top of ours, where we've truncated the variables `sheet_title` and `sheet_key` and suppressed the variable `ws_id` for readability.
    -
    -
     ```
    -## Source: local data frame [6 x 9]
    +## Source: local data frame [33 x 10]
     ## 
    -##   sheet_title    author perm version             updated  sheet_key
    -## 1  Ari's Anch  anahmani    r     old 2015-05-08 18:24:16 tQKSYVR...
    -## 2  #rhizo15 # m.hawksey    r     new 2015-05-08 18:51:36 1oBQNns...
    -## 3  EasyTweetS m.hawksey    r     new 2015-05-08 18:28:47 14mAbIi...
    -## 4  gas_mileag  woo.kara    r     new 2015-05-04 01:14:13 1WH65aJ...
    -## 5  #TalkPay T  iskaldur    r     new 2015-05-02 06:25:14 1IK1an_...
    -## 6  test-gs-ol  gspreadr   rw     old 2015-04-30 23:33:48 t0lmRSk...
    -## Variables not shown: alternate (chr), self (chr), alt_key (chr)
    +##                 sheet_title        author perm version             updated
    +## 1                       foo      gspreadr   rw     new 2015-05-08 22:14:30
    +## 2  Ari's Anchor Text Scrap…      anahmani    r     old 2015-05-08 18:24:16
    +## 3              #rhizo15 #tw     m.hawksey    r     new 2015-05-08 20:00:01
    +## 4   EasyTweetSheet - Shared     m.hawksey    r     new 2015-05-08 21:58:48
    +## 5               gas_mileage      woo.kara    r     new 2015-05-04 01:14:13
    +## 6           #TalkPay Tweets      iskaldur    r     new 2015-05-02 06:25:14
    +## 7        test-gs-old-sheet2      gspreadr   rw     old 2015-04-30 23:33:48
    +## 8    test-gs-mini-gapminder  rpackagetest    r     new 2015-04-25 18:25:43
    +## 9      test-gs-iris-private      gspreadr   rw     new 2015-04-25 15:18:05
    +## 10 1F0iNuYW4v_oG69s7c5Nzdo…      gspreadr   rw     new 2015-04-25 02:32:24
    +## ..                      ...           ...  ...     ...                 ...
    +## Variables not shown: sheet_key (chr), ws_feed (chr), alternate (chr), self
    +##   (chr), alt_key (chr)
     ```
     
    -This provides a nice overview of the spreadsheets you can access and is useful for looking up the __key__ of a spreadsheet (see below).
    +This provides a nice overview of the spreadsheets you can access.
     
     # Register a spreadsheet
     
    -Before you can access a spreadsheet, you must first __register__ it. This returns an object that is of little interest to the user, but is needed by various `googlesheets` functions in order to retrieve or edit spreadsheet data.
    +Before you can access a spreadsheet, you must first __register__ it. This returns a `googlesheets` object that is needed by downstream functions in order to retrieve or edit spreadsheet data.
     
    -Let's register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We can use `str()` to get an overview of the spreadsheet.
    +Let's register the Gapminder spreadsheet we spied in the list above and that you may have copied into your Google Drive. We have a nice `print` method for these objects, so print to screen for some basic info.
     
     
     ```r
    @@ -85,7 +89,7 @@ gap
     
     ```
     ##                   Spreadsheet title: Gapminder
    -##   Date of googlesheets registration: 2015-05-08 18:52:29 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
     ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
     ##                          visibility: private
     ##                         permissions: rw
    @@ -108,7 +112,7 @@ Besides using the spreadsheet title, you can also specify a spreadsheet in three
       * By URL: copy and paste the URL in your browser while visiting the spreadsheet.
       * By the "worksheets feed": under the hood, this is how `googlesheets` actually gets spreadsheet information from the API. Unlikely to be relevant to a regular user.
     
    -Here's an example of using the sheet title to retrieve the key, then registering the sheet by key. While registration by title is handy for interactive use, registration by key is preferred for scripts.
    +Here's an example of registering a sheet via key. While registration by title is handy for interactive use, registration by key might be preferred when programming.
     
     
     ```r
    @@ -134,7 +138,7 @@ ss2
     
     ```
     ##                   Spreadsheet title: Gapminder
    -##   Date of googlesheets registration: 2015-05-08 18:52:30 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
     ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
     ##                          visibility: private
     ##                         permissions: rw
    @@ -155,8 +159,9 @@ ss2
     
     Spreadsheet data is parcelled out into __worksheets__. To consume data from a Google spreadsheet, you'll need to specify a registered spreadsheet and, within that, a worksheet. Specify the worksheet either by name or positive integer index.
     
    -There are two ways to consume data.
    +There are three ways to consume data.
     
    +  * *The csv way ... bring this over from README*
       * The "list feed": only suitable for well-behaved tabular data. Think: data that looks like an R data.frame
       * The "cell feed": for everything else. Of course, you can get well-behaved tabular data with the cell feed but it's up to 3x slower and will require post-processing (reshaping and coercion).
       
    @@ -169,7 +174,7 @@ gap
     
     ```
     ##                   Spreadsheet title: Gapminder
    -##   Date of googlesheets registration: 2015-05-08 18:52:29 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:37 GMT
     ##     Date of last spreadsheet update: 2015-03-23 20:34:08 GMT
     ##                          visibility: private
     ##                         permissions: rw
    @@ -332,7 +337,7 @@ There are two basic modes of consuming data stored in a worksheet (quotes taken
     
     *Rework this for the new era.*
     
    -Under the hood, `gspread` functions must access a spreadsheet with either public or private __visiblity__. Visibility determines whether or not authorization will be used for a request.
    +Under the hood, `googlesheets` functions must access a spreadsheet with either public or private __visiblity__. Visibility determines whether or not authorization will be used for a request.
     
     No authorization is used when visibility is set to "public", which will only work for spreadsheets that have been "Published to the Web". Note that requests with visibility set to "public" __will not work__ for spreadsheets that are made "Public on the web" from the "Visibility options" portion of the sharing dialog of a Google Sheets file. In summary, "Published to the web" and "Public on the web" are __different__ ways to share a spreadsheet.
     
    @@ -354,7 +359,7 @@ To access public spreadsheets, you will either need the key of the spreadsheet (
     
     ### Add or delete spreadsheet
     
    -To add a spreadsheet to your Google Drive, use `gs_new()` and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled "Sheet1" by default. Recall we demonstrate the use of `copy_ss()` at the start of this vignette, which is another common way to get a new sheet.
    +To add a spreadsheet to your Google Drive, use `gs_new()` and simply pass in the title of the spreadsheet as a character string. The new spreadsheet will contain one worksheet titled "Sheet1" by default. Recall we demonstrate the use of `gs_copy()` at the start of this vignette, which is another common way to get a new sheet.
     
     or delete 
     or `gs_delete()` 
    @@ -377,7 +382,7 @@ gs_ls() %>% filter(sheet_title == "hi I am new here")
     ## Source: local data frame [1 x 10]
     ## 
     ##        sheet_title   author perm version             updated
    -## 1 hi I am new here gspreadr   rw     new 2015-05-08 18:52:31
    +## 1 hi I am new here gspreadr   rw     new 2015-05-08 22:14:39
     ## Variables not shown: sheet_key (chr), ws_feed (chr), alternate (chr), self
     ##   (chr), alt_key (chr)
     ```
    @@ -409,7 +414,7 @@ gs_ls() %>% filter(sheet_title == "hi I am new here")
     
     ### Add, delete, or rename a worksheet
     
    -To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local spreadsheet object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to `x` after adding the worksheet. This is because adding a worksheet changes the information associate with a registered sheet and, within editing function like `add_ws()`, we re-register the sheet and return the current sheet info.
    +To add a worksheet to a spreadsheet, pass in the spreadsheet object, title of new worksheet and the number of rows and columns. To delete a worksheet from a spreadsheet, pass in the spreadsheet object and the title of the worksheet. Note that after adding or deleting a worksheet, the local `googlesheet` object will not be automatically updated to include the new worksheet(s) information, you must register the spreadsheet again to update local knowledge about, e.g., the contituent worksheets. Notice that we store the sheet back to `x` after adding the worksheet. This is because adding a worksheet changes the information associated with a registered sheet and, within editing functions like `gs_ws_new()`, we re-register the sheet and return the current sheet info.
     
     
     ```r
    @@ -434,8 +439,8 @@ x
     
     ```
     ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:38 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:36 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:49 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:46 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -444,7 +449,7 @@ x
     ## (Title): (Nominal worksheet extent as rows x columns)
     ## Sheet1: 1000 x 26
     ## 
    -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM
     ```
     
     ```r
    @@ -461,8 +466,8 @@ x
     
     ```
     ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:39 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:38 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:49 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:49 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -472,7 +477,7 @@ x
     ## Sheet1: 1000 x 26
     ## foo: 10 x 10
     ## 
    -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM
     ```
     
     ```r
    @@ -498,8 +503,8 @@ x
     
     ```
     ##                   Spreadsheet title: hi I am new here
    -##   Date of googlesheets registration: 2015-05-08 18:52:40 GMT
    -##     Date of last spreadsheet update: 2015-05-08 18:52:39 GMT
    +##   Date of googlesheets registration: 2015-05-08 22:14:51 GMT
    +##     Date of last spreadsheet update: 2015-05-08 22:14:50 GMT
     ##                          visibility: private
     ##                         permissions: rw
     ##                             version: new
    @@ -508,7 +513,7 @@ x
     ## (Title): (Nominal worksheet extent as rows x columns)
     ## Sheet1: 1000 x 26
     ## 
    -## Key: 1upwcrqWI9F8xQxnR2y8CGVElZP82eAezI_uZ4Mwtiz8
    +## Key: 1t5RJT_v6fmljtJXVd01Me9bL6vGHJ11q1-XrSo2KvWM
     ```
     
     To rename a worksheet, pass in the spreadsheet object, the worksheet's current name and the new name you want it to be.