Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra ggplot2 lines trip up grade_this_code() #231

Open
garrettgman opened this issue Mar 5, 2021 · 1 comment
Open

Extra ggplot2 lines trip up grade_this_code() #231

garrettgman opened this issue Mar 5, 2021 · 1 comment
Labels
grade code Related to automatic code grading

Comments

@garrettgman
Copy link
Member

garrettgman commented Mar 5, 2021

Adding an extra call to a ggplot() call results in an obscure code suggestion: I expected ggplot() where you called +. For example, this learnr exercise

### 

__Edit your code from the previous exercise so that `marital` appears in order of increasing frequency.__ Use a forcats function to change the order.

```{r fct_rev, exercise =  TRUE}
gss_cat %>%
  ggplot(aes(marital)) + 
  geom_bar()
```

```{r fct_rev-solution}
gss_cat %>%
  ggplot(aes(fct_rev(fct_infreq(marital)))) + 
  geom_bar()
```

```{r fct_rev-check}
grade_this_code()
```

Returns the message below when a student supplies the code

gss_cat %>%
  ggplot(aes(fct_infreq(marital))) + 
  scale_x_discrete(limits = rev) +
  geom_bar()

Screen Shot 2021-03-05 at 10 38 57 AM

Since adding an extra line to a ggplot() call is a common failure mode for ggplot2, we should find a way to provide a better code suggestion.

One idea: perhaps the ggcheck package can come with a ggplot2 specific version of grade_this_code()that can begin by assuming it is working with ggplot2 code, e.g. grade_this_ggplot_code()

@gadenbuie
Copy link
Member

I think we should be able to fix this in gradethis. The underlying problem is that we don't do a good job of handling the case when there are more operations than expected:

# Extra addition
code_feedback("a + b + c", "a + c")
#> I didn't expect `+` where you wrote `a + b + c`.

# Extra addition, plus pipe (smaller reprex of the ggplot example)
code_feedback("x %>% a() + b + c", "a(x) + c")
#> In `x %>% a() + b + c`, I expected you to call `a()` where you called `+`.

# Extra pipes
code_feedback("x %>% a() %>% b() %>% c()", "x %>% a() %>% c()")
#> In `x %>% a() %>% b() %>% c()`, I expected you to call `a()` where you called `b()`.

We have an open issue for the extra pipe case: #185

@gadenbuie gadenbuie added the grade code Related to automatic code grading label Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grade code Related to automatic code grading
Projects
None yet
Development

No branches or pull requests

2 participants