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

Add praise and encourage arguments to graded() helpers #227

Merged
merged 5 commits into from
Mar 3, 2021

Conversation

gadenbuie
Copy link
Member

This PR adds praise and encourage arguments that follow the same pattern as hint.

I also added give_praise() and give_encouragement() which are small wrappers around an internal S3 generic give_random_phrase(). This follows the same pattern as give_code_feedback() and if we do this again we might want to think about one more layer of abstraction (but I'm hoping that we don't need to do this again for a while).

grader <- grade_this({
  if (.result <= 2) fail("Too low.")
  
  fail_if(.result == 3, "Not three.")
  fail_if_equal(4, "Not four.")
  
  if (.result == 5) pass("Five works!")
  pass_if(.result == 6, "Good six!")
  pass_if_equal(7, "Great seven!")
})

gradethis_setup(
  pass.praise = TRUE,
  fail.hint = TRUE,
  fail.encourage = TRUE
)

# Fails with encouragement
grader(mock_this_exercise(2))
#> <gradethis_graded: [Incorrect] Too low. But no need to fret, try it again.>
grader(mock_this_exercise(3))
#> <gradethis_graded: [Incorrect] Not three. Try it again. Perseverence is the key to success. Try it again; next time's the charm!>
# Fails with encouragement and a hint...
grader(mock_this_exercise(4, 5))
#> <gradethis_graded: [Incorrect] Not four. I expected `5` where you wrote `4`. That's okay: you learn more from mistakes than successes. Let's do it one more time.>

# Passes with praise...
grader(mock_this_exercise(5, 5))
#> <gradethis_graded: [Correct] Resplendent! Five works!>
grader(mock_this_exercise(6, 5))
#> <gradethis_graded: [Correct] I couldn't have done it better myself. :) Good six!>
grader(mock_this_exercise(7, 5))
#> <gradethis_graded: [Correct] Terrific! Great seven!>

Similarly, give_praise() and give_encouragement() can be used explicitly, although the global option is likely to be the most common usage pattern.

gradethis_setup(
  pass.praise = FALSE,
  fail.hint = FALSE,
  fail.encourage = FALSE
)

grader <- grader %>% give_praise() %>% give_encouragement()
# Fails with encouragement and a hint...
grader(mock_this_exercise(4, 5))
#> <gradethis_graded: [Incorrect] Not four. Try it again. I have a good feeling about this.>

# Passes with praise...
grader(mock_this_exercise(5, 5))
#> <gradethis_graded: [Correct] You should be proud. Five works!>

R/praise.R Show resolved Hide resolved
Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar behavior as give_code_feedback(). Exciting that the pattern is working!

@gadenbuie gadenbuie merged commit 4e2889e into rstudio:master Mar 3, 2021
@gadenbuie gadenbuie deleted the graded/praise-encourage branch March 3, 2021 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants