rstudio / gradethis

Tools for teachers to use with learnr
https://pkgs.rstudio.com/gradethis/
Other
161 stars 41 forks source link

Better handling of infix operators #84

Open chendaniely opened 5 years ago

chendaniely commented 5 years ago

given:

  user <-     quote(sqrt(1))
  solution <- quote(sqrt(1 + 2))
  expect_equal(
    detect_mistakes(user, solution)
    ,
    wrong_value(this = quote(1), that = "1 + 2")
  )

returns

Error: detect_mistakes(user, solution) not equal to wrong_value(this = quote(1), that = "1 + 2").
1/1 mismatches
x[1]: "I expected a call to `+`() where it was interpreted as 1."
y[1]: "I expected 1 + 2 where it was interpreted as 1."
garrettgman commented 4 years ago

Another error with +:

Screen Shot 2020-03-11 at 4 06 14 PM
gadenbuie commented 3 years ago

Here's a reprex as this stands now. @garrettgman do you have any suggestions for the messages we wish to see?

pkgload::load_all("~/work/gradethis")
#> Loading gradethis (a8f772102d5b51c2ff3810d45fb4f532f94d8a72)

code_feedback("sqrt(1)", "sqrt(1 + 2)")
#> In `sqrt(1)`, I expected `+` where you wrote `1`.

code_feedback("0 + sqrt(log(2))", "sqrt(log(2))")
#> I expected you to call `sqrt()` where you called `+`.
garrettgman commented 3 years ago

For infix operators , I think we need to say "something + something" instead of +. For example, the feedback message below

Screen Shot 2021-04-12 at 4 48 25 PM

Suggests to a new user that they should do this, which leads them to a frustrating dead end that they may not be able to see their way out of:

Screen Shot 2021-04-12 at 4 48 48 PM

A better message would be "In flipper_length_mm > bill_length_mm, I expected something * something where you wrote bill_length_mm." Alternatively, we could replace + with "a call to +()" in our messages, but new R users will have trouble interpreting that.

This replacement should generalize to all infix operators.

Should I open this as a separate issue? Its not clear to me what the thrust of Daniel's issue was.

gadenbuie commented 2 years ago

Here's another example.

```{r starwars-setup}
library(dplyr)
starwars %>%
  transmute(
    mass = as.integer(mass * 2.205),
    height = as.integer(height / 2.54)
  )
starwars %>%
  transmute(
    height = height / 2.54, 
    mass = mass * 2.205
  )
grade_this_table(check_column_order = TRUE)


> Your table’s columns were not in the expected order. The first 2 columns of your table should be `height` and `mass`.
> 
> I expected you to call `height = /` where you called `height = as.integer()`. Give it another try.