Skip to content

Grade check for SQL #201

Open
Open

Description

I am trying to implement check grading for SQL code. I tried to store result using dbGetQuery(connection, exercise$code) but it throws this error -

It looks like this might not be valid R code:

<text>:2:6: unexpected symbol
1: SELECT *
2: FROM `surveys`
               ^
R cannot determine how to turn your text into a complete command. You may have forgotten to fill in a blank, to remove an underscore, to include a comma between arguments, or to close an opening ", ', (, or { with a matching ", ', ), or }.

Code

---
title: "Multi-language exercises"
author: "Cass (Z.) Wilkinson Saldaña"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r setup, include = FALSE}
library(learnr)
library(gradethis)
 
# Tutorial Options
tutorial_options(exercise.lines = 10, exercise.timelimit = 60, 
                 exercise.checker = gradethis::grade_learnr)
knitr::opts_chunk$set(echo = FALSE)

if (!file.exists("portal_mammals.sqlite")) {
  download.file(url = "https://ndownloader.figshare.com/files/2292171",
                destfile = "portal_mammals.sqlite", mode = "wb")
}
mammals <- DBI::dbConnect(RSQLite::SQLite(), "portal_mammals.sqlite")
```

### SQL

Use a SQL connection defined in a setup chunk.

```{sql selectall, exercise = TRUE, connection="mammals"}
SELECT *
FROM `surveys`
LIMIT 10
```

```{r selectall-check}
grade_result(
  pass_if(~ all.equal(nrow(dbGetQuery(mammals, exercise$code)), 10), "Correct. Thumbs up!"))
```

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