Diagnosing Coding Errors with ChatGPT
Introduction
In this assignment, you will learn how to diagnose and resolve coding errors using ChatGPT. As a data analyst, it’s essential to develop the skill of identifying and fixing issues in your code. By using AI-assistants (e.g., ChatGPT) you can find solutions to common coding problems.
Instructions
1. Create a new quarto blog post for this assignment
2. Load the tidyverse package and read in the supermarket data set in
```{r}
library(tidyverse)
supermarket_sales <- read_csv("https://bus320-quarto.netlify.app/data/supermarket_sales.csv") ```
The dataset was created using ChatGPT and has the following variables:
invoice_id
: Unique identifier for each invoicebranch
: Branch location of the supermarketcity
: City where the supermarket is locatedcustomer_type
: Type of customer (Member or Normal)gender
: Gender of the customerproduct_line
: Category of the product purchasedunit_price
: Price per unit of the productquantity
: Number of units purchasedtax
: Tax applied to the purchasetotal
: Total amount of the purchase (includes tax)date
: Date of the purchasetime
: Time of the purchasepayment
: Payment method used (Cash or Credit card)cogs
: Cost of goods soldgross_margin_percentage
: Gross margin percentagegross_income
: Gross incomerating
: Customer rating of the purchase
3. Use glimpse to examine the data
- Insert a code chunk and
glimpse
the data
```{r}
glimpse(supermarket_sales)
```
4. Calculate total sales by city including tax
- Chunk with error
- Note: you need #| eval: false in the chunks with errors so when you render the post it will not evaluate that chunk
```{r}
#| eval: false
supermarket_sales |>
group_by(city) |>
summarise(total_sales = sum(total_price)) ```
- The error you receive when running the code is:
Use ChatGPT to identify the error in the code
The response from ChatGPT is (put in your own words):
Did the response explain the error:
Put the corrected version of the code in a chunk and re-run it.
```{r}
```
5. Count the number of sales by product_line and arrange counts in descending order
- Chuck with error
```{r}
#| eval: false
supermarket_sales |>
group_by(product_line) |>
count()
arrange(desc(n)) ```
- The error you receive when running the code is (put in your own words):
Use ChatGPT to identify the error in the code
The response from ChatGPT is
Did the response explain the error
Put the corrected version of the code in a chunk and re-run it.
```{r}
```
6. Create a horizontal barplot to display the average rating by product line.
```{r}
#| eval: false
supermarket_sales |>
group_by(product_line) |>
summarise(mean_rating = mean(rating)) |>
ggplot(aes(x = mean_rating, y = reorder(product_line, mean_rating))) |>
geom_col() |>
labs(y = NULL, x = NULL, title = "Average product rating by product line")
```
- The error you receive when running the code is:
Use ChatGPT to identify the error in the code
The response from ChatGPT is (put in your own words):
Did the response explain the error:
Put the corrected version of the code in a chunk and re-run it.
```{r}
```
Did you find the response from ChatGPT was more helpful than the error message? Explain.
How likely are you to use ChatGPT to assist you with programming? (1 = not likely… 5 = very likely) Explain.
Submit the link to your published quarto blog post on Camvas0.