Description Usage Arguments Details Value Column names Sorting and filtering via the API See Also Examples
Gets data via the "list feed", which assumes populated cells form a neat rectangle. The list feed consumes data row by row. The first row is assumed to hold variable or column names; it can be empty. The second row is assumed to hold the first data row and, if it is empty, no data will be read and you will get an empty data frame.
1 2 |
ss |
a registered Google spreadsheet, i.e. a |
ws |
positive integer or character string specifying index or title, respectively, of the worksheet |
reverse |
logical, optional. Indicates whether to request reverse row order in the actual API call. |
orderby |
character, optional. Specifies a column to sort on in the actual API call. |
sq |
character, optional. Provides a structured query for row filtering in the actual API call. |
... |
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.
|
verbose |
logical; do you want informative messages? |
The other read functions are generally superior, so use them if you can.
However, you may need to use this function if you are dealing with an "old"
Google Sheet, which is beyond the reach of gs_read_csv
. The
list feed also has some ability to sort and filter rows via the API (more
below). Consult the Google Sheets API documentation for more details about
the
list feed.
a data.frame
or, if dplyr
is loaded, a
tbl_df
For the list feed, and only for the list feed, the Sheets API wants to
transform the variable or column names like so: 'The column names are the
header values of the worksheet lowercased and with all non-alpha-numeric
characters removed. For example, if the cell A1 contains the value "Time 2
Eat!" the column name would be "time2eat".' In googlesheets
, we do
not let this happen and, instead, use the column names "as is", for
consistent output across all gs_read*
functions. If you direct
gs_read_listfeed
to pass query parameters to the actual API call,
you must refer to variables using the column names under this
API-enforced transformation. For example, to order the data by the column
with "Time 2 Eat!" in the header row, you must specify orderby =
"time2eat"
in the gs_read_listfeed
call.
Why on earth would you want to sort and filter via the API instead of in R?
Just because you can? It is conceivable there are situations, such as a
large spreadsheet, in which it is faster to sort or filter via API. Be sure
to refer to variables using the API-transformed column names explained
above! It is a
known
bug that reverse=true
alone will NOT, in fact, reverse the row
order of the result. In our experience, the reverse
query parameter
will only have effect in combination with explicit specification of a
column to sort on via orderby
. The syntax for these queries
is
apparently undocumented, so keep it simple or bring your spirit of
adventure!
Other data consumption functions: gs_read_cellfeed
,
gs_read_csv
, gs_read
,
gs_reshape_cellfeed
,
gs_simplify_cellfeed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## Not run:
gap_ss <- gs_gap() # register the Gapminder example sheet
oceania_lf <- gs_read_listfeed(gap_ss, ws = "Oceania")
head(oceania_lf, 3)
## do row ordering and filtering in the API call
oceania_fancy <-
gs_read_listfeed(gap_ss,
ws = "Oceania",
reverse = TRUE, orderby = "gdppercap",
sq = "lifeexp > 79 or year < 1960")
oceania_fancy
## passing args through to readr::type_convert()
oceania_crazy <-
gs_read_listfeed(gap_ss,
ws = "Oceania",
col_names = paste0("z", 1:6), skip = 1,
col_types = "ccncnn",
na = "1962")
oceania_crazy
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.