Skip to content

Commit

Permalink
Addin for inserting check code and check result chunks (rstudio#31)
Browse files Browse the repository at this point in the history
* addin for inserting check code and check result chunks

* add example code inside pass_if and fail_if
  • Loading branch information
chendaniely authored and schloerke committed Jul 15, 2019
1 parent 9e304c9 commit 2ac1820
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
62 changes: 62 additions & 0 deletions R/insert_exercise_check_code.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
insert_exercise_check_code <- function() {
random_chunk_label <- generate_random_chunk_label()

rstudioapi::insertText(glue::glue("
```{r <<random_chunk_label>>, exercise = TRUE}
# student code
```
```{r <<random_chunk_label>>-hint-1}
# hint text
```
```{r <<random_chunk_label>>-hint-2}
# hint text
```
```{r <<random_chunk_label>>-solution}
# solution code
```
```{r <<random_chunk_label>>-check}
# check code
grader::check_code()
```
" , .open = "<<", .close = ">>"))
}

insert_exercise_check_result <- function() {
random_chunk_label <- generate_random_chunk_label()

rstudioapi::insertText(glue::glue("
```{r <<random_chunk_label>>, exercise = TRUE}
# student code
```
```{r <<random_chunk_label>>-hint-1}
# hint text
```
```{r <<random_chunk_label>>-hint-2}
# hint text
```
```{r <<random_chunk_label>>-check}
grader::check_result(
grader::pass_if(~ .result == 1),
grader::fail_if(~ .result == 2)
)
```
" , .open = "<<", .close = ">>"))
}

generate_random_chunk_label <- function() {
paste0(sample(letters, 16, replace = TRUE), collapse = '')
}
9 changes: 9 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Name: Insert exercise: check code
Description: Inserts code chunks to do code checking at the cursor position.
Binding: insert_exercise_check_code
Interactive: false

Name: Insert exercise: check result
Description: Inserts code chunks to do result checking at the cursor position.
Binding: insert_exercise_check_result
Interactive: false

0 comments on commit 2ac1820

Please sign in to comment.