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.
read_gsheets(ss, col_types = NULL, .id = NULL)
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.
Something that identifies a Google Sheet:
Processed through as_sheets_id()
.
Column types. Either NULL
to guess all from the
spreadsheet or a string of readr-style shortcodes, with one character or
code per column. If exactly one col_type
is specified, it is recycled.
See Column Specification for more.
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.
googlesheets4::read_sheet()
which reads a Google (spread)Sheet into a data frame.
if (FALSE) { # googlesheets4::gs4_has_token()
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,
}
if (FALSE) { # googlesheets4::gs4_has_token()
sheet_id <- "1rrjKAV05POre9lDVtHtZePTa8VROf1onVO47cHnhrTU"
try(read_gsheets(ss = sheet_id)) # error, column types mismatch
read_gsheets(ss = sheet_id, col_types = "c")
}
Run the code above in your browser using DataLab