Skip to content

API design: use pass_if() and fail_if() #3

@andrie

Description

@andrie

Intent: use a similar API to the grader project, as described in rstudio/gradethis#11

In a nutshell, you should be able to write:

  • initial contains the initial value
  • pass_if()
  • fail_if()

For both pass_if() and fail_if(), support:

  • character vector, and pass if exact match
  • function in the traditional form function(x)...
  • function using formula form ~. == ...
```{r iris, echo=FALSE}
question_parsons(
  initial = c(
    "iris",
    "mutate(...)",
    "summarize(...)",
    "print()"
  ),
  pass_if(
    c(
      "iris",
      "mutate(...)",
      "summarize(...)"
    )
  ),
  pass_if(...),
  fail_if(
    ~length(.) < 2,
    message = "Include at least two answers"
  ),
  fail_if(
    function(x){"print()" %in% x},
    message = "You should not include print() in your answer"
  ),
  fail_if(
    function(x){x[1] != "iris"},
    message = "Your solution should start with 'iris'"
  )
)
```

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