---
title: 'Lab 7: Importing Data'
format:
  html:
    embed-resources: true
editor: source
knitr:
  opts_chunk:
    message: false
---

###### Question 1
Use the `library()` function to load the `tidyverse`, `janitor`, and `googlesheets4` packages.

###### Question 2
Spend a minute reviewing the README file in the coffee quality rating GitHub repository. Which of the following is **not** an aspect the coffees were rated on?

a. Body
b. Cup Cleanliness
c. Bitterness
d. Moisture


###### Question 3
Insert a new code chunk in your Quarto document, and copy the code template below into this code chunk.

Then, copy the "raw" URL for the [robusta_ratings_raw.csv]{.filename} from GitHub, and paste this URL inside the call to `read_csv()`. **Don't forget to put quotation marks around the URL!**

Use the `<-` assignment operator to store the output from the `read_csv()` function in an object named `robusta_raw`.

Finally, confirm that the data was imported correctly by printing the `robusta_raw` object.

###### Question 4

Use `glimpse()` to get a quick overview of the `robusta_raw` data.
Then, use the output from `glimpse()` to answer the following questions.

a. How many variables are measured in these data?
b. How many variables have names with `...` in them?
c. How many variables have names with spaces in them?


###### Question 5
Insert a new code chunk in your Quarto document, and copy the code template below into this code chunk.

Fill in the blank inside the `clean_names()` function with the `robusta_raw` data frame object.
Then, use the `<-` assignment operator to store the output from the `clean_names()` function in a new data frame object named `robusta_cleaned`.

Finally, run the `glimpse()` function to inspect the newly created `robusta_cleaned` data frame. How have the variable names changed after using the `clean_names()` function?

###### Question 6

Investigate the online repository for the [avengers](https://github.com/fivethirtyeight/data/tree/master/avengers){target="_blank"} data from FiveThirtyEight, which is all about [Marvel comic book characters](https://en.wikipedia.org/wiki/Avengers_(comics)){target="_blank"}. 

Then, import the [avengers.csv]{.filename} file, and then clean up the variable names.
Finally, use the glimpse function to answer the following question: how many variable's in this data set contain numeric data?

###### Question 7
Insert a new code chunk into your Quarto document, and copy the code template below into this chunk.

Then, navigate to the Gapminder Google Sheet, and copy the URL from the address bar.
Paste this the URL inside the call to the `read_sheet()` function, with quotation marks around the URL.
Next, use the assignment operator to store the output from the `read_sheet()` function in an object named `gapminder`.
Finally, confirm that the data was imported correctly by printing the `gapminder` object.

###### Question 8
Above, we discussed the difference between `read_sheet()` and `read_csv()`. 
Copy your code from the previous answer into a new code chunk below. Then, replace 
`read_sheet()` with `read_csv()`, and run the code again (this command may take a several moments to finish running).

What happens when you use `read_csv()` instead of `read_sheet()` on a Google Sheet URL? _Hint:_ Consider the number of rows and columns. Is this what you expect?

###### Question 9
Extract the data file named [product review text.csv]{.filename} from the zip file you downloaded, and move it into your [SDS 100]{.filename} project folder.

If you've never extracted files from a zip file before, here are some instructions you might find helpful:

- `r fontawesome::fa("windows")` [Unzipping a file on Windows](https://support.google.com/chromebook/answer/1700055)
- `r fontawesome::fa("apple")` [Unzipping a file on MacOS](https://support.apple.com/guide/mac-help/zip-and-unzip-files-and-folders-on-mac-mchlp2528/mac)
- `r fontawesome::fa("chrome")` [Unzipping a file on ChromeOS](https://support.google.com/chromebook/answer/1700055)

###### Question 10
Use the `locale()` function (which comes from the `readr` package) to create an object representing a Chinese locale that uses the GB18030 encoding, just like the example below:

Then, try using the `read_csv()` function to import the [product review text.csv]{.filename} file and store the data in an object named `JD_product_reviews` again. But *this* time, pass the locale object you created into the `read_csv()` function using the `locale` argument.

Check that the data were imported properly by printing out the `JD_product_reviews` object; the data should look like the screenshot above.

