Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
machinations necessary for success w/ CRAN submission [skip ci]
Browse files Browse the repository at this point in the history
suppress execution of certain vignette chunks on CRAN
  * to still build the full vignette locally, make sure envvar NOT_CRAN is TRUE
  * I forgot to do this and submitted a largely unexecuted vignette :(
  * I figure I'll need to update for other reasons before too long and can re-submit vignette at same time

 make sure the *unencrypted* token is not sent to CRAN
  * list the token in tests/testthat in .Rbuildignore
  * this will cause tests to fail on travis (hence we are skipping ci)
  • Loading branch information
jennybc committed Jul 6, 2015
1 parent 32e5ad8 commit 8ce9aa7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ rsconnect
^cran-comments.md$
^README.html$
tests/testthat/googlesheets_token.rds.enc
tests/testthat/googlesheets_token.rds
4 changes: 4 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
* ubuntu 12.04 on travis-ci, R 3.2.1
* win-builder, devel and release 3.2.1

This is a resubmission. In the previous submission, Kurt remarked on the fact that CRAN could not re-build the vignette outputs, since the vignette uses the package to make authenticated calls to the Google Sheets API. However, there is no way to securely provide an access token to CRAN. Therefore I have followed his advice to conditionally suppress evaluation of these specific chunks. This has cleared the NOTE about the vignette.

## R CMD check results

There were no ERRORs or WARNINGs.

There is one NOTE:

Note #1:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Jennifer Bryan <[email protected]>'
New submission
Expand Down
39 changes: 25 additions & 14 deletions vignettes/basic-usage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ vignette: >
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
fig.path = "README-",
purl = FALSE
)
if(identical(tolower(Sys.getenv("NOT_CRAN")), "true")) {
NOT_CRAN <- TRUE
} else {
NOT_CRAN <- FALSE
}
```

```{r auth, include = FALSE}
```{r 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))
```

```{r pre-clean, include = 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
googlesheets::gs_vecdel(c("foo", "iris"), verbose = FALSE)
Expand All @@ -43,7 +49,7 @@ suppressMessages(library(dplyr))

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).

```{r list-sheets}
```{r list-sheets, eval = NOT_CRAN}
(my_sheets <- gs_ls())
# (expect a prompt to authenticate with Google interactively HERE)
my_sheets %>% glimpse()
Expand All @@ -68,7 +74,7 @@ If you plan to consume data from a sheet or edit it, you must first __register__

*We're using the built-in functions `gs_gap_key()` and `gs_gap_url()` to produce the key and browser URL for the Gapminder example sheet, so you can see how this will play out with your own projects.*

```{r register-sheet}
```{r register-sheet, eval = NOT_CRAN}
gap <- gs_title("Gapminder")
gap
Expand All @@ -90,6 +96,11 @@ third_party_gap <- GAP_URL %>%
gap <- gap %>% gs_gs()
```

```{r register-sheet-cran-only, include = FALSE, eval = !NOT_CRAN}
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.*
Expand Down Expand Up @@ -215,7 +226,7 @@ gap_1col %>% gs_simplify_cellfeed(notation = "none", col_names = TRUE)

You can use `googlesheets` to create new spreadsheets.

```{r new-sheet}
```{r new-sheet, eval = NOT_CRAN}
foo <- gs_new("foo")
foo
```
Expand All @@ -233,7 +244,7 @@ If you have the choice, `gs_add_row()` is faster, but it can only be used when y

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.

```{r edit-cells}
```{r edit-cells, eval = NOT_CRAN}
## foo <- gs_new("foo")
## initialize the worksheets
foo <- foo %>% gs_ws_new("edit_cells")
Expand Down Expand Up @@ -268,7 +279,7 @@ Read the function documentation for `gs_edit_cells()` for how to specify where t

Let's clean up by deleting the `foo` spreadsheet we've been playing with.

```{r delete-sheet}
```{r delete-sheet, eval = NOT_CRAN}
gs_delete(foo)
```

Expand All @@ -278,7 +289,7 @@ If you'd rather specify sheets for deletion by title, look at `gs_grepdel()` and

Here's how we can create a new spreadsheet from a suitable local file. First, we'll write then upload a comma-delimited excerpt from the iris data.

```{r new-sheet-from-file}
```{r new-sheet-from-file, eval = NOT_CRAN}
iris %>%
head(5) %>%
write.csv("iris.csv", row.names = FALSE)
Expand All @@ -290,15 +301,15 @@ file.remove("iris.csv")

Now we'll upload a multi-sheet Excel workbook. Slowly.

```{r new-sheet-from-xlsx}
```{r 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")
```

And we clean up after ourselves on Google Drive.

```{r delete-moar-sheets}
```{r delete-moar-sheets, eval = NOT_CRAN}
gs_vecdel(c("iris", "mini-gap"))
## achieves same as:
## gs_delete(iris_ss)
Expand All @@ -309,7 +320,7 @@ gs_vecdel(c("iris", "mini-gap"))

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}
```{r export-sheet-as-csv, eval = NOT_CRAN}
gs_title("Gapminder") %>%
gs_download(ws = "Africa", to = "gapminder-africa.csv")
## is it there? yes!
Expand All @@ -318,7 +329,7 @@ read.csv("gapminder-africa.csv") %>% head()

Download the entire spreadsheet as an Excel workbook.

```{r export-sheet-as-xlsx}
```{r export-sheet-as-xlsx, eval = NOT_CRAN}
gs_title("Gapminder") %>%
gs_download(to = "gapminder.xlsx")
```
Expand All @@ -327,7 +338,7 @@ Go check it out in Excel, if you wish!

And now we clean up the downloaded files.

```{r clean-exported-files}
```{r clean-exported-files, eval = NOT_CRAN}
file.remove(c("gapminder.xlsx", "gapminder-africa.csv"))
```

Expand Down

0 comments on commit 8ce9aa7

Please sign in to comment.