read_gsheets {bulkreadr} | R Documentation |
Import data from multiple sheets in Google Sheets
Description
The read_gsheets()
function imports data from multiple sheets in a Google Sheets spreadsheet and appends the resulting dataframes from each sheet together to create a single dataframe. This function is a powerful tool for data analysis, as it allows you to easily combine data from multiple sheets into a single dataset.
Usage
read_gsheets(ss, col_types = NULL, .id = NULL)
Arguments
ss |
Something that identifies a Google Sheet:
Processed through |
col_types |
Column types. Either |
.id |
The name of an optional identifier column. Provide a string to create an output column that identifies each input. The column will use names if available, otherwise it will use positions. |
Value
A tibble. If there is any column type mismatch during data frames row binding, an error will occur. This is because R cannot combine columns of different types. For example, you cannot combine a column of integers with a column of characters.
See Also
read_sheet()
which reads a Google (spread)Sheet into a data frame.
Examples
sheet_id <- "1izO0mHu3L9AMySQUXGDn9GPs1n-VwGFSEoAKGhqVQh0"
read_gsheets(ss = sheet_id, .id = "sheet.name")
# Column types mismatch error --------------------------------------
# If the `read_gsheets()` function complains about a data type mismatch,
# then set the `col_types` argument to `"c"`.
# This will make all the column types in the resulting dataframe be characters.
# For example,
sheet_id <- "1rrjKAV05POre9lDVtHtZePTa8VROf1onVO47cHnhrTU"
try(read_gsheets(ss = sheet_id)) # error, column types mismatch
read_gsheets(ss = sheet_id, col_types = "c")