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

Commit

Permalink
rework paths in vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jul 1, 2015
1 parent e81ab71 commit b744009
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 88 deletions.
17 changes: 10 additions & 7 deletions vignettes/basic-usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ suppressMessages(googlesheets::gs_auth(token = token_path, verbose = FALSE))
## ----pre-clean, include = FALSE------------------------------------------
## if a previous compilation of this document leaves anything behind, i.e. if it
## aborts, clean up Google Drive first
googlesheets::gs_vecdel("hi I am new here", verbose = FALSE)
googlesheets::gs_vecdel(c("foo", "iris"), verbose = FALSE)
file.remove(c("gapminder.xlsx", "gapminder-africa.csv", "iris"))

## ----load package--------------------------------------------------------
library(googlesheets)
Expand Down Expand Up @@ -140,11 +141,13 @@ 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)
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)
foo <- foo %>%
gs_edit_cells(ws = "add_row", input = head(iris, 1), trim = TRUE)
## add the next 5 rows of data
for(i in 2:6) {
foo <- foo %>% gs_add_row(ws = "add_row", input = iris[i, ])
Expand Down Expand Up @@ -179,16 +182,16 @@ gs_vecdel(c("iris", "mini-gap"))

## ----export-sheet-as-csv-------------------------------------------------
gs_title("Gapminder") %>%
gs_download(ws = "Africa", to = "~/tmp/gapminder-africa.csv")
gs_download(ws = "Africa", to = "gapminder-africa.csv")
## is it there? yes!
read.csv("~/tmp/gapminder-africa.csv") %>% head()
read.csv("gapminder-africa.csv") %>% head()

## ----export-sheet-as-xlsx------------------------------------------------
gs_title("Gapminder") %>%
gs_download(to = "~/tmp/gapminder.xlsx")
gs_download(to = "gapminder.xlsx")

## ----clean-exported-files------------------------------------------------
file.remove(file.path("~/tmp", c("gapminder.xlsx", "gapminder-africa.csv")))
file.remove(c("gapminder.xlsx", "gapminder-africa.csv"))

## ----gs_auth, eval = FALSE-----------------------------------------------
# # Give googlesheets permission to access your spreadsheets and google drive
Expand Down
17 changes: 10 additions & 7 deletions vignettes/basic-usage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ suppressMessages(googlesheets::gs_auth(token = token_path, verbose = FALSE))
```{r pre-clean, include = FALSE}
## if a previous compilation of this document leaves anything behind, i.e. if it
## aborts, clean up Google Drive first
googlesheets::gs_vecdel("hi I am new here", verbose = FALSE)
googlesheets::gs_vecdel(c("foo", "iris"), verbose = FALSE)
file.remove(c("gapminder.xlsx", "gapminder-africa.csv", "iris"))
```

```{r load package}
Expand Down Expand Up @@ -239,11 +240,13 @@ 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)
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)
foo <- foo %>%
gs_edit_cells(ws = "add_row", input = head(iris, 1), trim = TRUE)
## add the next 5 rows of data
for(i in 2:6) {
foo <- foo %>% gs_add_row(ws = "add_row", input = iris[i, ])
Expand Down Expand Up @@ -307,24 +310,24 @@ You can download a Google Sheet as a csv, pdf, or xlsx file. Downloading the spr

```{r export-sheet-as-csv}
gs_title("Gapminder") %>%
gs_download(ws = "Africa", to = "~/tmp/gapminder-africa.csv")
gs_download(ws = "Africa", to = "gapminder-africa.csv")
## is it there? yes!
read.csv("~/tmp/gapminder-africa.csv") %>% head()
read.csv("gapminder-africa.csv") %>% head()
```

Download the entire spreadsheet as an Excel workbook.

```{r export-sheet-as-xlsx}
gs_title("Gapminder") %>%
gs_download(to = "~/tmp/gapminder.xlsx")
gs_download(to = "gapminder.xlsx")
```

Go check it out in Excel, if you wish!

And now we clean up the downloaded files.

```{r clean-exported-files}
file.remove(file.path("~/tmp", c("gapminder.xlsx", "gapminder-africa.csv")))
file.remove(c("gapminder.xlsx", "gapminder-africa.csv"))
```

### Authorization using OAuth2
Expand Down
Loading

0 comments on commit b744009

Please sign in to comment.