diff --git a/.Rbuildignore b/.Rbuildignore index 26e5bfa..2a95de4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,10 +1,10 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^\.httr-oauth$ -^\.httr-oauth_REVOKED$ +^\.httr-oauth-SUSPENDED$ ^vignettes/\.httr-oauth$ ^tests/testthat/\.httr-oauth$ -^tests/testthat/\.httr-oauth_REVOKED$ +^tests/testthat/\.httr-oauth-SUSPENDED$ vignettes/basic-usage.Rmd ^\.travis\.yml$ ^internal-projects$ diff --git a/DESCRIPTION b/DESCRIPTION index d3cba04..b0d9163 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Depends: License: MIT + file LICENSE LazyData: true Imports: - cellranger (== 0.1.0), + cellranger (>= 1.0.0), dplyr (>= 0.4.0), ggplot2, httr (>= 0.6.1), diff --git a/R/gs_cell-specification.R b/R/gs_cell-specification.R index 465b714..08a235e 100644 --- a/R/gs_cell-specification.R +++ b/R/gs_cell-specification.R @@ -69,8 +69,8 @@ limit_list <- function(x) { stopifnot(inherits(x, "cell_limits") || is.null(x)) if(inherits(x, "cell_limits")) { - retval <- list(`min-row` = x$rows[1], `max-row` = x$rows[2], - `min-col` = x$cols[1], `max-col` = x$cols[2]) + retval <- list(`min-row` = x$ul[1], `max-row` = x$lr[1], + `min-col` = x$ul[2], `max-col` = x$lr[2]) retval[is.na(retval)] <- NULL } @@ -84,7 +84,7 @@ limit_list <- function(x) { un_limit_list <- function(x) { - cellranger::cell_limits(rows = c(x[['min-row']], x[['max-row']]), - cols = c(x[['min-col']], x[['max-col']])) + cellranger::cell_limits(ul = c(x[['min-row']], x[['min-col']]), + lr = c(x[['max-row']], x[['max-col']])) } diff --git a/R/gs_edit_cells.R b/R/gs_edit_cells.R index fa23d5a..14545a2 100644 --- a/R/gs_edit_cells.R +++ b/R/gs_edit_cells.R @@ -65,16 +65,8 @@ gs_edit_cells <- function(ss, ws = 1, input = '', anchor = 'A1', catch_hopeless_input(input) this_ws <- gs_ws(ss, ws, verbose = FALSE) - ## I can edit/remove this once cellranger updates on CRAN and the default - ## behavior of anchored() is smarter - if(is.null(dim(input))) { - col_names <- FALSE - } else if(is.null(col_names)) { - col_names <- !is.null(colnames(input)) - } - - limits <- ## change header to col_names after cellranger updates - cellranger::anchored(anchor, input = input, header = col_names, + limits <- + cellranger::anchored(anchor = anchor, input = input, col_names = col_names, byrow = byrow) ## TO DO: if I were really nice, I would use the positioning notation from the ## user, i.e. learn it from anchor, instead of defaulting to A1 @@ -97,6 +89,14 @@ gs_edit_cells <- function(ss, ws = 1, input = '', anchor = 'A1', } + ## redundant with the default col_names-setting logic from cellranger :( + ## but we need it here as well to pass directions to as_character_vector() + if(is.null(dim(input))) { # input is 1-dimensional + col_names <- FALSE + } else if(is.null(col_names)) { + col_names <- !is.null(colnames(input)) + } + input <- input %>% as_character_vector(col_names = col_names) cells_df <- ss %>% @@ -192,7 +192,6 @@ catch_hopeless_input <- function(x) { as_character_vector <- function(x, col_names) { catch_hopeless_input(x) - x_colnames <- NULL ## instead of fiddly tests on x (see comments below), just go with it, if x diff --git a/R/gs_read_cellfeed.R b/R/gs_read_cellfeed.R index 1c05a26..4ba1587 100644 --- a/R/gs_read_cellfeed.R +++ b/R/gs_read_cellfeed.R @@ -55,12 +55,6 @@ gs_read_cellfeed <- function( stopifnot(inherits(ss, "googlesheet")) this_ws <- gs_ws(ss, ws, verbose) - if(is.null(range)) { - ## once cellranger updates on CRAN, can remove this - ## because as.cell_limits() will natively do the right thing for NULL - ## https://github.com/jennybc/cellranger/commit/c9c9080ca0fdf1db97c8ea935f00c6bcc10d6e0b - range <- cell_limits() - } limits <- range %>% cellranger::as.cell_limits() %>% limit_list() diff --git a/README.Rmd b/README.Rmd index a6f7f64..453a1e4 100644 --- a/README.Rmd +++ b/README.Rmd @@ -167,7 +167,7 @@ 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, 5), c(4, NA))) +gap %>% gs_read(ws = "Asia", range = cell_limits(c(1, 4), c(5, NA))) ``` `gs_read()` is a wrapper that bundles together the most common methods to read data from the API and transform it for downstream use. You can refine it's behavior further, by passing more arguments via `...`. Read the help file for more details. @@ -241,7 +241,7 @@ gap %>% # arbitrary cell range, direct specification of column names gap %>% - gs_read_cellfeed("Oceania", range = cell_limits(c(2, 5), c(1, 3))) %>% + 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 = "_")) ``` diff --git a/README.md b/README.md index 33f7f30..5274fbc 100644 --- a/README.md +++ b/README.md @@ -76,31 +76,31 @@ The `gs_ls()` function returns the sheets you would see in your Google Sheets ho ``` r (my_sheets <- gs_ls()) -#> Source: local data frame [40 x 10] +#> Source: local data frame [39 x 10] #> #> sheet_title author perm version updated -#> 1 Copy of Twitter Archive… joannazhaoo r new 2015-06-02 06:28:25 -#> 2 yo gspreadr rw new 2015-06-02 00:18:40 -#> 3 TAGS v6.0ns m.hawksey r new 2015-06-01 22:12:36 -#> 4 EasyTweetSheet - Shared m.hawksey r new 2015-06-01 15:10:09 -#> 5 #rhizo15 #tw m.hawksey r new 2015-06-01 15:41:47 -#> 6 Ari's Anchor Text Scrap… anahmani r new 2015-05-29 07:18:48 -#> 7 Tweet Collector (TAGS v… gspreadr rw new 2015-05-28 17:43:29 -#> 8 test-gs-cars-private gspreadr rw new 2015-05-27 17:48:34 -#> 9 All R Phylo Functions omeara.brian r new 2015-05-20 18:34:43 -#> 10 test-gs-public-testing-… rpackagetest r new 2015-05-20 01:32:27 +#> 1 Copy of Twitter Archive… joannazhaoo r new 2015-06-20 23:31:25 +#> 2 gas_mileage woo.kara r new 2015-06-20 01:31:26 +#> 3 EasyTweetSheet - Shared m.hawksey r new 2015-06-18 16:07:23 +#> 4 TAGS v6.0ns m.hawksey r new 2015-06-08 17:55:05 +#> 5 Supervisor Interests (R… silwood.mast… r new 2015-06-08 08:59:51 +#> 6 Projects_2013_14 david.orme r new 2015-06-08 08:59:44 +#> 7 #rhizo15 #tw m.hawksey r new 2015-06-01 15:41:47 +#> 8 Ari's Anchor Text Scrap… anahmani r new 2015-05-29 07:18:48 +#> 9 Tweet Collector (TAGS v… gspreadr rw new 2015-05-28 17:43:29 +#> 10 test-gs-cars-private gspreadr rw new 2015-05-27 17:48:34 #> .. ... ... ... ... ... #> Variables not shown: sheet_key (chr), ws_feed (chr), alternate (chr), self #> (chr), alt_key (chr) # (expect a prompt to authenticate with Google interactively HERE) my_sheets %>% glimpse() -#> Observations: 40 +#> Observations: 39 #> Variables: -#> $ sheet_title (chr) "Copy of Twitter Archiver v2.1", "yo", "TAGS v6.0n... -#> $ author (chr) "joannazhaoo", "gspreadr", "m.hawksey", "m.hawksey... -#> $ perm (chr) "r", "rw", "r", "r", "r", "r", "rw", "rw", "r", "r... +#> $ sheet_title (chr) "Copy of Twitter Archiver v2.1", "gas_mileage", "E... +#> $ author (chr) "joannazhaoo", "woo.kara", "m.hawksey", "m.hawksey... +#> $ perm (chr) "r", "r", "r", "r", "r", "r", "r", "r", "rw", "rw"... #> $ version (chr) "new", "new", "new", "new", "new", "new", "new", "... -#> $ updated (time) 2015-06-02 06:28:25, 2015-06-02 00:18:40, 2015-06... +#> $ updated (time) 2015-06-20 23:31:25, 2015-06-20 01:31:26, 2015-06... #> $ sheet_key (chr) "1DoMXh2m3FGPoZAle9vnzg763D9FESTU506iqWkUTwtE", "1... #> $ ws_feed (chr) "https://spreadsheets.google.com/feeds/worksheets/... #> $ alternate (chr) "https://docs.google.com/spreadsheets/d/1DoMXh2m3F... @@ -132,7 +132,8 @@ gap <- gs_title("Gapminder") #> Sheet successfully identifed: "Gapminder" gap #> Spreadsheet title: Gapminder -#> Date of googlesheets registration: 2015-06-02 06:33:37 GMT +#> Spreadsheet author: gspreadr +#> Date of googlesheets registration: 2015-06-20 23:34:46 GMT #> Date of last spreadsheet update: 2015-03-23 20:34:08 GMT #> visibility: private #> permissions: rw @@ -272,7 +273,7 @@ gap %>% gs_read(ws = "Africa", range = cell_cols(1:4)) #> 9 Algeria Africa 1992 67.744 #> 10 Algeria Africa 1997 69.152 #> .. ... ... ... ... -gap %>% gs_read(ws = "Asia", range = cell_limits(c(1, 5), c(4, NA))) +gap %>% gs_read(ws = "Asia", range = cell_limits(c(1, 4), c(5, NA))) #> Accessing worksheet titled "Asia" #> Source: local data frame [4 x 3] #> @@ -389,9 +390,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.060 0.358 1.438 -#> sys.self 0.001 0.010 0.043 -#> elapsed 0.342 0.856 2.574 +#> user.self 0.057 0.360 1.421 +#> sys.self 0.002 0.011 0.044 +#> elapsed 0.384 1.004 3.022 #> user.child 0.000 0.000 0.000 #> sys.child 0.000 0.000 0.000 ``` @@ -493,7 +494,7 @@ gap %>% # arbitrary cell range, direct specification of column names gap %>% - gs_read_cellfeed("Oceania", range = cell_limits(c(2, 5), c(1, 3))) %>% + 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 = "_")) #> Accessing worksheet titled "Oceania" @@ -598,8 +599,9 @@ foo <- gs_new("foo") #> Worksheet dimensions: 1000 x 26. foo #> Spreadsheet title: foo -#> Date of googlesheets registration: 2015-06-02 06:33:54 GMT -#> Date of last spreadsheet update: 2015-06-02 06:33:52 GMT +#> Spreadsheet author: gspreadr +#> Date of googlesheets registration: 2015-06-20 23:35:06 GMT +#> Date of last spreadsheet update: 2015-06-20 23:35:05 GMT #> visibility: private #> permissions: rw #> version: new @@ -608,7 +610,7 @@ foo #> (Title): (Nominal worksheet extent as rows x columns) #> Sheet1: 1000 x 26 #> -#> Key: 1j6ng7vMWmRvI2CE1pzMhTK7vEuHBPdjUzgDVR8lR7LQ +#> Key: 1YjkRLrB_ECIbJsHAurcmqgzIDLs1ZDUgnBieKoCLlVo ``` 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()`. @@ -671,8 +673,9 @@ 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-06-02 06:34:07 GMT -#> Date of last spreadsheet update: 2015-06-02 06:34:05 GMT +#> Spreadsheet author: gspreadr +#> Date of googlesheets registration: 2015-06-20 23:35:19 GMT +#> Date of last spreadsheet update: 2015-06-20 23:35:18 GMT #> visibility: private #> permissions: rw #> version: new @@ -681,7 +684,7 @@ iris_ss #> (Title): (Nominal worksheet extent as rows x columns) #> iris: 6 x 5 #> -#> Key: 1KiGs1pMgNqL31xlyvvH1jHSCccinnFC1zgf_l1mtVbY +#> Key: 1fp6LF7F1hb5q-ZVdmqD_BipV4dzrRBAWvCvelKf0D5w iris_ss %>% gs_read() #> Accessing worksheet titled "iris" #> Source: local data frame [5 x 5] @@ -703,8 +706,9 @@ 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-06-02 06:34:11 GMT -#> Date of last spreadsheet update: 2015-06-02 06:34:09 GMT +#> Spreadsheet author: gspreadr +#> Date of googlesheets registration: 2015-06-20 23:35:24 GMT +#> Date of last spreadsheet update: 2015-06-20 23:35:22 GMT #> visibility: private #> permissions: rw #> version: new @@ -717,7 +721,7 @@ gap_xlsx #> Europe: 1000 x 26 #> Oceania: 1000 x 26 #> -#> Key: 1CARCS6TkakYeJMvNB-Um8Gi9lPI3X9M7HFfETeutOiY +#> Key: 1RuOmo-PsXeXVjjZIW5u6nBt0Dq9xhiaAB_364rA2Wvs gap_xlsx %>% gs_read(ws = "Asia") #> Accessing worksheet titled "Asia" #> Source: local data frame [5 x 6] @@ -800,11 +804,12 @@ The function `gs_user()` will print and return some information about the curren ``` r user_session_info <- gs_user() -#> displayName: google sheets -#> emailAddress: gspreadr@gmail.com -#> Date-time of session authorization: 2015-06-02 06:33:32 -#> Date-time of access token expiry: 2015-06-02 00:30:49 -#> Access token is valid. +#> displayName: google sheets +#> emailAddress: gspreadr@gmail.com +#> date: 2015-06-20 23:34:44 GMT +#> access token: valid +#> peek at access token: ya29....MqV7Q +#> peek at refresh token: 1/egc...4epw8 user_session_info #> $displayName #> [1] "google sheets" @@ -812,11 +817,17 @@ user_session_info #> $emailAddress #> [1] "gspreadr@gmail.com" #> -#> $auth_date -#> [1] "2015-06-02 06:33:32 GMT" +#> $date +#> [1] "2015-06-20 23:34:44 GMT" #> -#> $exp_date -#> [1] "2015-06-02 00:30:49 PDT" +#> $token_valid +#> [1] TRUE +#> +#> $peek_acc +#> [1] "ya29....MqV7Q" +#> +#> $peek_ref +#> [1] "1/egc...4epw8" ``` ### "Old" Google Sheets diff --git a/tests/testthat/test-cell-edit.R b/tests/testthat/test-cell-edit.R index cb66a0a..e6503ee 100644 --- a/tests/testthat/test-cell-edit.R +++ b/tests/testthat/test-cell-edit.R @@ -41,7 +41,7 @@ test_that("Input converts to character vector (or not)", { test_that("Single cell can be updated", { - expect_message(ss <- gs_edit_cells(ss, ws, "eggplant", "A1"), + expect_message(ss <- gs_edit_cells(ss, ws, "eggplant"), "successfully updated") Sys.sleep(1) tmp <- ss %>% diff --git a/tests/testthat/test-yy-consume-data-public-selective.R b/tests/testthat/test-yy-consume-data-public-selective.R index d52ae69..710fd12 100644 --- a/tests/testthat/test-yy-consume-data-public-selective.R +++ b/tests/testthat/test-yy-consume-data-public-selective.R @@ -3,21 +3,21 @@ context("consume data with public visibility, selectively") ## consuming data owned by someone else, namely rpackagetest ss <- gs_ws_feed(GAP_WS_FEED, lookup = FALSE, verbose = FALSE) -test_that("We can get data from specific cells using a limits", { +test_that("We can get data from specific cells using limits", { ## fully specify limits foo <- ss %>% - gs_read_cellfeed(ws = 5, range = cell_limits(c(3, 5), c(1, 3))) + gs_read_cellfeed(ws = 5, range = cell_limits(c(3, 1), c(5, 3))) expect_equal(foo$cell, paste0(LETTERS[1:3], rep(3:5, each = 3))) ## partially specified limits foo <- ss %>% - gs_read_cellfeed(ws = "Oceania", range = cell_limits(c(2, NA), c(4, 4))) + gs_read_cellfeed(ws = "Oceania", range = cell_limits(c(2, 4), c(NA, 4))) expect_true(all(grepl("^D", foo$cell))) ## partially specified limits foo <- ss %>% - gs_read_cellfeed(ws = "Oceania", range = cell_limits(cols = c(NA, 3))) + gs_read_cellfeed(ws = "Oceania", range = cell_limits(lr = c(NA, 3))) expect_true(all(grepl("^[ABC][0-9]+$", foo$cell))) })