Allow several ways to respond with learnr

67 Views Asked by At

I am developing a tutorial using learnr (using gradethis to check codes). Here is my set-up chunk.

    ```{r setup, include=FALSE}
    library(learnr)
    library(gapminder)
    gm <- data.frame(gapminder)
    
    library(tidyverse)
    tutorial_options(exercise.timelimit = 60)
    gradethis::gradethis_setup(allow_partial_matching=TRUE)
    ```

Here is the simple exercise:

Using gm, find the the GDP of Zimbabwe in 1997

```{r gdpzim, exercise=TRUE}
gm[...,...]
```

```{r gdpzim-solution, exercise.reveal_solution = FALSE}
gm[gm$country == "Zimbabwe" & gm$year==1997,  "gdpPercap"]
```

```{r gdpzim-code-check}
grade_this_code()
```

```{r gdpzim-check}
sol <- gm[gm$country == "Zimbabwe" & gm$year==1997,  "gdpPercap"]
grade_result(
  pass_if(~identical(.result, sol ))
)
```

I would like to find so that code-check accepts both:

gm[gm$country == "Zimbabwe" & gm$year==1997,  "gdpPercap"]

or

gm[gm$year==1997 & gm$country == "Zimbabwe" ,  "gdpPercap"]

As it is now, the second solution is rejected.

This is just a generic question, since there are often different ways to write a solution that is acceptable for a given problem.

0

There are 0 best solutions below