Learn R Programming

googlesheets (version 0.2.0)

gs_read: Read data

Description

This function reads data from a worksheet and returns a data frame. It wraps up the most common usage of other, lower-level functions for data consumption and transformation, but you can call always call them directly for finer control.

Usage

gs_read(ss, ws = 1, range = NULL, literal = TRUE, ..., verbose = TRUE)

Arguments

ss
a registered Google spreadsheet, i.e. a googlesheet object
ws
positive integer or character string specifying index or title, respectively, of the worksheet
range
a cell range, as described in cell-specification
literal
logical, indicating whether to work only with literal values returned by the API or to consult alternate cell contents
...
Optional arguments to control data download, parsing, and reshaping; for most purposes, the defaults should be fine. Anything that is not listed here will be silently ignored. [object Object],[object Object],[object Object],[object Ob
verbose
logical; do you want informative messages?

Value

  • a data.frame or, if dplyr is loaded, a tbl_df

Details

If the range argument is not specified and literal = TRUE, all data will be read via gs_read_csv. Don't worry -- no intermediate *.csv files are written! We just request the data from the Sheets API via the exportcsv link.

If the range argument is specified or if literal = FALSE, data will be read for the targetted cells via gs_read_cellfeed, then reshaped and type converted with gs_reshape_cellfeed. See gs_reshape_cellfeed for details.

See Also

The cell-specification topic for more about targetting specific cells.

Other data.consumption.functions: gs_read_cellfeed, gs_read_csv, gs_read_listfeed, gs_reshape_cellfeed, gs_simplify_cellfeed

Examples

Run this code
gap_ss <- gs_gap()
oceania_csv <- gs_read(gap_ss, ws = "Oceania")
str(oceania_csv)
oceania_csv

gs_read(gap_ss, ws = "Europe", n_max = 4, col_types = c("cccccc"))

gs_read(gap_ss, ws = "Oceania", range = "A1:C4")
gs_read(gap_ss, ws = "Oceania", range = "R1C1:R4C3")
gs_read(gap_ss, ws = "Oceania", range = "R2C1:R4C3", col_names = FALSE)
gs_read(gap_ss, ws = "Oceania", range = "R2C5:R4C6",
        col_names = c("thing_one", "thing_two"))
gs_read(gap_ss, ws = "Oceania", range = cell_limits(c(1, 3), c(1, 4)),
        col_names = FALSE)
gs_read(gap_ss, ws = "Oceania", range = cell_rows(1:5))
gs_read(gap_ss, ws = "Oceania", range = cell_cols(4:6))
gs_read(gap_ss, ws = "Oceania", range = cell_cols("A:D"))

ff_ss <- gs_ff() # register example sheet with formulas and formatted nums
gs_read(ff_ss)                  # almost all vars are character
gs_read(ff_ss, literal = FALSE) # more vars are properly numeric

Run the code above in your browser using DataLab