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

Commit

Permalink
Merge pull request #121 from jennybc/refactor-sheet-listing-registration
Browse files Browse the repository at this point in the history
Refactor sheet listing and registration; rename almost everything
  • Loading branch information
Jennifer (Jenny) Bryan committed May 8, 2015
2 parents 5931e0e + 5c038e8 commit 3aefeb3
Show file tree
Hide file tree
Showing 86 changed files with 2,270 additions and 2,261 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: googlesheets
Title: Manage your Google spreadsheets in R
Version: 0.0.0.9000
Version: 0.0.0.9001
Description: R API for Google Spreadsheets
Authors@R: c(
person("Jennifer", "Bryan", , "jenny@stat.ubc.ca", c("aut", "cre")),
Expand Down
29 changes: 16 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

S3method(print,googlesheet)
S3method(print,googlesheet_ls)
export(add_ws)
export(authorize)
export(copy_ss)
export(delete_ss)
export(delete_ws)
export(download_ss)
export(edit_cells)
export(extract_key_from_url)
export(get_cells)
Expand All @@ -16,14 +10,23 @@ export(get_row)
export(get_via_cf)
export(get_via_csv)
export(get_via_lf)
export(gs_auth)
export(gs_copy)
export(gs_delete)
export(gs_download)
export(gs_grepdel)
export(gs_key)
export(gs_ls)
export(identify_ss)
export(list_sheets)
export(list_ws)
export(new_ss)
export(register_ss)
export(rename_ws)
export(gs_new)
export(gs_title)
export(gs_upload)
export(gs_url)
export(gs_vecdel)
export(gs_ws_delete)
export(gs_ws_feed)
export(gs_ws_ls)
export(gs_ws_new)
export(gs_ws_rename)
export(reshape_cf)
export(simplify_cf)
export(upload_ss)
importFrom(dplyr,"%>%")
26 changes: 13 additions & 13 deletions R/consume-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' oceania_csv <- get_via_csv(gap_ss, ws = "Oceania")
#' str(oceania_csv)
#' oceania_csv
Expand All @@ -34,14 +34,14 @@ get_via_csv <- function(ss, ws = 1, ..., verbose = TRUE) {

stopifnot(ss %>% inherits("googlesheet"))

this_ws <- get_ws(ss, ws, verbose)
this_ws <- gs_ws(ss, ws, verbose)

if(is.null(this_ws$exportcsv)) {
stop(paste("This appears to be an \"old\" Google Sheet. The old Sheets do",
"not offer the API access required by this function.",
"Consider converting it from an old Sheet to a new Sheet.",
"Or use another data consumption function, such as get_via_lf()",
"or get_via_cf(). Or use download_ss() to export it to a local",
"or get_via_cf(). Or use gs_download() to export it to a local",
"file and then read it into R."))
}

Expand Down Expand Up @@ -94,7 +94,7 @@ get_via_csv <- function(ss, ws = 1, ..., verbose = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' oceania_lf <- get_via_lf(gap_ss, ws = "Oceania")
#' str(oceania_lf)
#' oceania_lf
Expand All @@ -105,7 +105,7 @@ get_via_lf <- function(ss, ws = 1, verbose = TRUE) {

stopifnot(ss %>% inherits("googlesheet"))

this_ws <- get_ws(ss, ws, verbose)
this_ws <- gs_ws(ss, ws, verbose)
req <- gsheets_GET(this_ws$listfeed)

ns <- xml2::xml_ns_rename(xml2::xml_ns(req$content), d1 = "feed")
Expand Down Expand Up @@ -178,7 +178,7 @@ get_via_lf <- function(ss, ws = 1, verbose = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' get_via_cf(gap_ss, "Asia", max_row = 4)
#' reshape_cf(get_via_cf(gap_ss, "Asia", max_row = 4))
#' reshape_cf(get_via_cf(gap_ss, "Asia",
Expand All @@ -195,7 +195,7 @@ get_via_cf <-

stopifnot(ss %>% inherits("googlesheet"))

this_ws <- get_ws(ss, ws, verbose)
this_ws <- gs_ws(ss, ws, verbose)

if(is.null(limits)) {
limits <- list("min-row" = min_row, "max-row" = max_row,
Expand Down Expand Up @@ -303,7 +303,7 @@ get_via_cf <-
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' get_row(gap_ss, "Europe", row = 1)
#' simplify_cf(get_row(gap_ss, "Europe", row = 1))
#' }
Expand All @@ -329,7 +329,7 @@ get_row <- function(ss, ws = 1, row, verbose = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' get_col(gap_ss, "Oceania", col = 1:2)
#' reshape_cf(get_col(gap_ss, "Oceania", col = 1:2))
#' }
Expand All @@ -356,7 +356,7 @@ get_col <- function(ss, ws = 1, col, verbose = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' get_cells(gap_ss, "Europe", range = "B3:D7")
#' simplify_cf(get_cells(gap_ss, "Europe", range = "A1:F1"))
#' }
Expand All @@ -382,7 +382,7 @@ get_cells <- function(ss, ws = 1, range, verbose = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- copy_ss(key = gap_key, to = "gap_copy")
#' gap_ss <- gs_copy(gs_key(gap_key), to = "gap_copy")
#' get_via_cf(gap_ss, "Asia", max_row = 4)
#' reshape_cf(get_via_cf(gap_ss, "Asia", max_row = 4))
#' }
Expand Down Expand Up @@ -428,7 +428,7 @@ reshape_cf <- function(x, header = TRUE) {
dplyr::select_(~ row, ~ col, ~ cell_text) %>%
tidyr::spread_("col", "cell_text", convert = TRUE) %>%
dplyr::select_(~ -row) %>%
setNames(var_names)
stats::setNames(var_names)
}

#' Simplify data from the cell feed
Expand Down Expand Up @@ -460,7 +460,7 @@ reshape_cf <- function(x, header = TRUE) {
#' @examples
#' \dontrun{
#' gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
#' gap_ss <- register_ss(gap_key)
#' gap_ss <- gs_key(gap_key)
#' get_row(gap_ss, row = 1)
#' simplify_cf(get_row(gap_ss, row = 1))
#' simplify_cf(get_row(gap_ss, row = 1), notation = "R1C1")
Expand Down
109 changes: 0 additions & 109 deletions R/download-spreadsheets.R

This file was deleted.

21 changes: 11 additions & 10 deletions R/edit-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
#'
#' @examples
#' \dontrun{
#' yo <- new_ss("yo")
#' yo <- gs_new("yo")
#' yo <- edit_cells(yo, input = head(iris), header = TRUE, trim = TRUE)
#' get_via_csv(yo)
#'
#' yo <- add_ws(yo, "byrow_FALSE")
#' yo <- gs_ws_new(yo, "byrow_FALSE")
#' yo <- edit_cells(yo, ws = "byrow_FALSE", LETTERS[1:5], "A8")
#' get_via_cf(yo, ws = "byrow_FALSE", min_row = 7) %>% simplify_cf()
#'
#' yo <- add_ws(yo, "byrow_TRUE")
#' yo <- gs_ws_new(yo, "byrow_TRUE")
#' yo <- edit_cells(yo, ws = "byrow_TRUE", LETTERS[1:5], "A8", byrow = TRUE)
#' get_via_cf(yo, ws = "byrow_TRUE", min_row = 7) %>% simplify_cf()
#' }
Expand All @@ -46,7 +46,7 @@ edit_cells <- function(ss, ws = 1, input = '', anchor = 'A1',
verbose = TRUE) {

catch_hopeless_input(input)
this_ws <- get_ws(ss, ws, verbose = FALSE)
this_ws <- gs_ws(ss, ws, verbose = FALSE)


limits <-
Expand All @@ -65,10 +65,10 @@ edit_cells <- function(ss, ws = 1, input = '', anchor = 'A1',
if(limits$`max-row` > this_ws$row_extent ||
limits$`max-col` > this_ws$col_extent) {
ss <- ss %>%
resize_ws(this_ws$ws_title,
max(this_ws$row_extent, limits$`max-row`),
max(this_ws$col_extent, limits$`max-col`),
verbose)
gs_ws_resize(this_ws$ws_title,
max(this_ws$row_extent, limits$`max-row`),
max(this_ws$col_extent, limits$`max-col`),
verbose)
Sys.sleep(1)

}
Expand Down Expand Up @@ -136,11 +136,12 @@ edit_cells <- function(ss, ws = 1, input = '', anchor = 'A1',

Sys.sleep(1)
ss <- ss %>%
resize_ws(this_ws$ws_title, limits$`max-row`, limits$`max-col`, verbose)
gs_ws_resize(this_ws$ws_title, limits$`max-row`,
limits$`max-col`, verbose)
}

Sys.sleep(1)
ss <- ss %>% register_ss(verbose = FALSE)
ss <- ss$sheet_key %>% gs_key(verbose = FALSE)
invisible(ss)
}

Expand Down
Loading

0 comments on commit 3aefeb3

Please sign in to comment.