You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gradethis must be loaded globally using library(gradethis) otherwise code_feedback cannot be found.
mocked<-gradethis::mock_this_exercise("rnorm(10)", "rnorm(10)")
gradethis::grade_this_code()(mocked)
#> #> (gradethis::grade_this_code())(mocked)#> Error in do_grade_this(): could not find function "code_feedback"#> <gradethis_graded_this_code: [Neutral]#> A problem occurred with the grading code for this exercise.#> >
If you just want to compare code, you can call code_feedback() directly. It returns NULL if the user code is correct, or a (hopefully) helpful message as a character string if not.
gradethis::code_feedback("rnorm(10)", "rnorm(100)")
#> In `rnorm(10)`, I expected `100` where you wrote `10`.
Thank you! I'm having a bit of a tough time following the documentation since I am trying to use gradethis outside of the context of learnr so using pass() and fail() doesn't make much sense to me because you need to pass in the .result which is available from grade_this_code() and not code_feedback().
using pass() and fail() doesn't make much sense to me because you need to pass in the .result
pass() and fail() don't need a result, they just take a string with the message you want to show. Here's a simple example with a light-weight grade_this_code() that doesn't do any user code evaluation.
code_grade(user_wrong, solution)
#> <gradethis_graded: [Incorrect]#> In `rnorm(100)`, I expected `10` where you wrote `100`. That's okay:#> you learn more from mistakes than successes. Let's do it one more#> time.#> >
You can get the final pass/fail message directly from $message, but the graded object carries a small amount of additional information you might find useful.
Activity
gadenbuie commentedon Jul 2, 2024
If you just want to compare code, you can call
code_feedback()directly. It returnsNULLif the user code is correct, or a (hopefully) helpful message as a character string if not.JosiahParry commentedon Jul 3, 2024
Thanks! It's not a complete replacement. Instead, I can use gradethis::random_praise() when the result is correct (NULL)
gadenbuie commentedon Jul 3, 2024
You could also use the
pass()andfail()helpers: https://pkgs.rstudio.com/gradethis/reference/graded.htmlJosiahParry commentedon Jul 3, 2024
Thank you! I'm having a bit of a tough time following the documentation since I am trying to use gradethis outside of the context of learnr so using
pass()andfail()doesn't make much sense to me because you need to pass in the.resultwhich is available fromgrade_this_code()and notcode_feedback().gadenbuie commentedon Jul 3, 2024
pass()andfail()don't need a result, they just take a string with the message you want to show. Here's a simple example with a light-weightgrade_this_code()that doesn't do any user code evaluation.You can get the final pass/fail message directly from
$message, but the graded object carries a small amount of additional information you might find useful.