Skip to content

Can gradethis::grade_this use checks on the provided code (not the evaluated results) #361

Open

Description

@RaymondBalise

I know I can test for an exact match on a student's code using grade_this_code() but is there a way to check for an exact match on what was typed as an answer on the code using grade_this().

I am working on teaching students about the type of vectors used by R. I want students to use typeof() to realize that R returns the major version of R as a character string (because it is a number that will not be used for math):

```{r ex2-typeof-solution, exercise.reveal_solution = TRUE}
typeof(R.version$major)
```

I see students providing: typeof(R.version$nickname) as a solution. That, like the correct answer of typeof(R.version$major), returns a character string. So it is being called a correct answer.

Is there a way to trap the case that students type a specific response inside of grade_this()? I think you can see what I am getting at using this code

```{r ex2-typeof-check}
grade_this({
  # I want to see if they typed this text
  fail_if_equal(.user_code == "typeof(R.version$nickname)", 
    message = "You are checking the nickname you want to be checking the major"
  )
  pass_if_equal(typeof(R.version$major), 
    message = "Interesting the version number is being treated as a character string. R does not want you to do math on the version number."
  )
  fail_if_equal(R.version$major,
    message = "Your code is telling you the major version. You want to check the type using `typeof()`."              
  )
  fail_if_equal(R.version,
    message = "That code tells you everything about the R version. Add a `$` and the key word for the `major` version."              
  )  
  fail(message = "Not quite. Take a peek at the hints!")
})
```

I see that .user_code captures the provided text but I don't see how to use it in a logic check.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions