Skip to content

Commit

Permalink
Make invisible result warning opt-in (#373)
Browse files Browse the repository at this point in the history
Co-authored-by: Nischal Shrestha <nsrocker92@gmail.com>
  • Loading branch information
nischalshrestha and nischalshrestha committed Jul 14, 2020
1 parent 5a061d0 commit 859c946
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Remotes: rstudio/htmltools
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Suggests:
testthat (>= 2.1.0),
callr,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ learnr (development version)
* Added `include=FALSE` to setup chunks to prevent exercises from printing out messages or potential code output for those setup chunks. ([#390](https://github.com/rstudio/learnr/pull/390))
* Added error handling when user specificies a non-existent label for `exercise.setup` option with an error message. ([#390](https://github.com/rstudio/learnr/pull/390))
* We no longer forward the checker code to browser (in html), but instead cache it. ([#390](https://github.com/rstudio/learnr/pull/390))
* We no longer display an invisible exercise result warning automatically. Instead, authors must set the exercise chunk option `exercise.warn_invisible = TRUE` to display an invisible result warning message. ([#373](https://github.com/rstudio/learnr/pull/373))

## Bug fixes

Expand Down
8 changes: 5 additions & 3 deletions R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,13 @@ evaluate_exercise <- function(exercise, envir, evaluate_global_setup = FALSE) {
NULL
}

warn_invisible_result <- isTRUE(exercise$options$exercise.warn_invisible)

if (
# if the last value was invisible
!last_value_is_visible &&
# if the checker function exists
is.function(checker)
# if the warn invisible is set
warn_invisible_result
) {
# works with NULL feedback
feedback_html <- htmltools::tagList(feedback_html, invisible_feedback())
Expand Down Expand Up @@ -554,7 +556,7 @@ invisible_feedback <- function() {
feedback_as_html(
feedback_validated(
list(
message = "Last value being used to check answer is invisible. See `?invisible` for more information",
message = "Note: Last value being returned is invisible. See `?invisible` for more information",
type = "warning",
correct = FALSE,
location = "append"
Expand Down
4 changes: 4 additions & 0 deletions docs/exercises.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Exercises are interactive R code chunks that allow readers to directly execute R
<td><code>exercise.startover</code></td>
<td>Whether to include a "Start Over" button for the exercise.</td>
</tr>
<tr class="odd">
<td><code>exercise.warn_invisible</code></td>
<td>Whether to display an invisible result warning if the last value returned is invisible.</td>
</tr>
</tbody>
</table>

Expand Down
8 changes: 8 additions & 0 deletions docs/exercises.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ <h2>Overview</h2>
Whether to include a “Start Over” button for the exercise.
</td>
</tr>
<tr class="odd">
<td>
<code>exercise.warn_invisible</code>
</td>
<td>
Whether to display an invisible result warning if the last value returned is invisible.
</td>
</tr>
</tbody>
</table>
<p>Note that these options can all be specified either globally or per-chunk. For example, the following code sets global default options using the <code>setup</code> chunk and also sets some local options on the <code>addition</code> chunk:</p>
Expand Down

0 comments on commit 859c946

Please sign in to comment.