forked from rstudio/gradethis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addin for inserting check code and check result chunks (rstudio#31)
* addin for inserting check code and check result chunks * add example code inside pass_if and fail_if
- Loading branch information
1 parent
9e304c9
commit 2ac1820
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |