Updates so URL fits on a single line

This commit is contained in:
mine-cetinkaya-rundel 2023-05-09 15:19:10 -04:00
parent 9ef9685618
commit 45aee03c4b
1 changed files with 9 additions and 7 deletions

View File

@ -554,7 +554,9 @@ This is the same dataset as in @fig-students-excel, except it's stored in a Goog
knitr::include_graphics("screenshots/import-googlesheets-students.png")
```
The first argument to `read_sheet()` is the URL of the file to read, and it returns a tibble:
The first argument to `read_sheet()` is the URL of the file to read, and it returns a tibble:\
<https://docs.google.com/spreadsheets/d/1V1nPp1tzOuutXFLb3G9Eyxi3qxeEhnOXUzL5_BcCQ0w>.
These URLs are not pleasant to work with, so you'll often want to identify a sheet by its ID.
```{r}
#| include: false
@ -563,8 +565,8 @@ gs4_deauth()
```
```{r}
students_url <- "https://docs.google.com/spreadsheets/d/1V1nPp1tzOuutXFLb3G9Eyxi3qxeEhnOXUzL5_BcCQ0w"
students <- read_sheet(students_url)
students_sheet_id <- "1V1nPp1tzOuutXFLb3G9Eyxi3qxeEhnOXUzL5_BcCQ0w"
students <- read_sheet(students_sheet_id)
students
```
@ -572,7 +574,7 @@ Just like we did with `read_excel()`, we can supply column names, NA strings, an
```{r}
students <- read_sheet(
students_url,
students_sheet_id,
col_names = c("student_id", "full_name", "favourite_food", "meal_plan", "age"),
skip = 1,
na = c("", "N/A"),
@ -589,14 +591,14 @@ It's also possible to read individual sheets from Google Sheets as well.
Let's read the "Torgersen Island" sheet from the [penguins Google Sheet](https://pos.it/r4ds-penguins):
```{r}
penguins_url <- "https://docs.google.com/spreadsheets/d/1aFu8lnD_g0yjF5O-K6SFgSEWiHPpgvFCF0NY9D6LXnY"
read_sheet(penguins_url, sheet = "Torgersen Island")
penguins_sheet_id <- "1aFu8lnD_g0yjF5O-K6SFgSEWiHPpgvFCF0NY9D6LXnY"
read_sheet(penguins_sheet_id, sheet = "Torgersen Island")
```
You can obtain a list of all sheets within a Google Sheet with `sheet_names()`:
```{r}
sheet_names(penguins_url)
sheet_names(penguins_sheet_id)
```
Finally, just like with `read_excel()`, we can read in a portion of a Google Sheet by defining a `range` in `read_sheet()`.