compare_reply_answer: Compare a reply to an answer

Description Usage Arguments Examples

View source: R/compare-reply-answer.R

Description

The comparison is done via a numerical grid.

Usage

1
2
3
4
5
6
7
8
9
compare_reply_answer(
  reply,
  answer,
  compare_grid = NULL,
  replace_comma = TRUE,
  ans_tol = 0.01,
  insert_products = TRUE,
  allowed_functions = getGroupMembers("Math")
)

Arguments

reply

user-provided reply as string/character matrix (will be evaluated safely)

answer

the true answer provided as an R expression (or list of list of expressions; first level are columns, then rows)

compare_grid

grid to perform comparisons on; must have columns

replace_comma

Replace ',' with '.' before parsing

ans_tol

tolerance for comparisons

insert_products

Make implicit products explicit

allowed_functions

functions (sequence of characters) that should not have products, e.g. cos, sin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
compare_reply_answer(reply = "2yx^2", 
                     answer = expression("2*y*x^2"), 
                     compare_grid = expand.grid(x = seq(-10, 10, len = 10), 
                                                y = seq(-10, 10, len = 10)))
compare_reply_answer(reply = "2.1yx^2", 
                     answer = expression("2*y*x^2"), 
                     compare_grid = expand.grid(x = seq(-10, 10, len = 10), 
                                                y = seq(-10, 10, len = 10)))
compare_reply_answer(reply = "2yx^2+0.01", 
                     answer = expression("2*y*x^2"), 
                     compare_grid = expand.grid(x = seq(-10, 10, len = 10), 
                                                y = seq(-10, 10, len = 10)), 
                     ans_tol = 1)
                     
rep <- matrix(c("(1+1)*x", "3*x"), nrow = 1, ncol = 2)
ans <- list(list(expression(2*x)), list(expression(3*x)))
compare_reply_answer(reply = rep,
                     answer = ans,
                     compare_grid = expand.grid(x = seq(-10, 10, len = 10)),
                     ans_tol = 1)

r-cas/iomath documentation built on May 28, 2021, 11:10 p.m.