Skip to content

Commit

Permalink
Add default arguments to gradethis_equal() (#347)
Browse files Browse the repository at this point in the history
Co-authored-by: rossellhayes <[email protected]>
  • Loading branch information
rossellhayes and rossellhayes committed May 13, 2023
1 parent 1ecb441 commit 712fcfa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: gradethis
Title: Automated Feedback for Student Exercises in 'learnr' Tutorials
Version: 0.2.12.9004
Version: 0.2.12.9005
Authors@R: c(
person("Garrick", "Aden-Buie", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-7111-0077")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# gradethis 0.2.12.9005

* `gradethis_equal()` now has default arguments of `x = .result` and `y = .solution` (#347).
* `gradethis_equal.default()` now has a default argument of `tolerance = sqrt(.Machine$double.eps)`.

# gradethis 0.2.12.9004

* Add `fail_if_not_equal()` (#346).
Expand Down
15 changes: 13 additions & 2 deletions R/gradethis_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@
#' @examples
#' gradethis_equal(mtcars[mtcars$cyl == 6, ], mtcars[mtcars$cyl == 6, ])
#' gradethis_equal(mtcars[mtcars$cyl == 6, ], mtcars[mtcars$cyl == 4, ])
gradethis_equal <- function(x, y, ...) {
gradethis_equal <- function(x = .result, y = .solution, ...) {
if (is_placeholder(x) || is_placeholder(y)) {
x <- resolve_placeholder(x)
y <- resolve_placeholder(y)
return(gradethis_equal(x, y, ...))
}

UseMethod("gradethis_equal")
}

#' @describeIn gradethis_equal
#' The default comparison method, which uses [waldo::compare]
#' @inheritParams waldo::compare
#' @export
gradethis_equal.default <- function(x, y, tolerance, ...) {
gradethis_equal.default <- function(
x,
y,
tolerance = sqrt(.Machine$double.eps),
...
) {
local_options_waldo_compare()

tryCatch(
Expand Down
11 changes: 6 additions & 5 deletions man/gradethis_equal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/pass_if_equal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 712fcfa

Please sign in to comment.