Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make invisible result warning opt-in #373

Merged
merged 7 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,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
!checker_fn_does_not_exist
# 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 @@ -457,7 +459,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
1 change: 1 addition & 0 deletions R/knitr-hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ install_knitr_hooks <- function() {
preserved_options$exercise.timelimit <- options$exercise.timelimit
preserved_options$exercise.setup <- options$exercise.setup
preserved_options$exercise.checker <- deparse(options$exercise.checker)
preserved_options$exercise.warn_invisible <- options$exercise.warn_invisible

# script tag with knit options for this chunk
extra_html <- c('<script type="application/json" data-opts-chunk="1">',
Expand Down
1 change: 0 additions & 1 deletion docs/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Examples</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
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
19 changes: 13 additions & 6 deletions docs/exercises.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Exercises</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -488,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 Expand Up @@ -526,7 +533,7 @@ <h2>Exercise Setup</h2>

</div>
<script type="text/javascript">loadSnippet('exercisesetupshared')</script></li>
<li><p>Create a setup chunk that’s specific to another chunk using a <code>-setup</code> chunk suffix. To do this give your exercise chunk a label (e.g. <code>filter</code>) then add another chunk with the same label plus a <code>-setup</code> suffix (e.g. <code>filter-setup</code>). For example:</p>
<li><p>Create a setup chunk that’s specific to another chunk using a <code>-setup</code> chunk suffix. To do this give your exercise chunk a label (e.g. <code>filter</code>) then add another chunk with the same label plus a <code>-setup</code> suffix (e.g. <code>filter-setup</code>). For example:</p>
<div id="exercisesetupsuffix" style="width: 95%;">

</div>
Expand All @@ -548,7 +555,7 @@ <h3>R Code Hints</h3>
</div>
<div id="markdown-hints" class="section level3">
<h3>Markdown Hints</h3>
<p>To create a hint based on custom markdown content simply add a <code>&lt;div&gt;</code> tag with an <code>id</code> attribue that marks it as hint for your exercise (e.g. “filter-hint”). For example:</p>
<p>To create a hint based on custom markdown content simply add a <code>&lt;div&gt;</code> tag with an <code>id</code> attribue that marks it as hint for your exercise (e.g. “filter-hint”). For example:</p>
<div id="exercisehintdiv">

</div>
Expand All @@ -557,7 +564,7 @@ <h3>Markdown Hints</h3>
</div>
<div id="multiple-hints" class="section level3">
<h3>Multiple Hints</h3>
<p>For R code hints you can provide a sequence of hints that reveal progressively more of the solution as desired by the user. To do this create a sequence of indexed hint chunks (e.g. “-hint-1”, “-hint-2,”-hint-3", etc.) for your exercise chunk. For example:</p>
<p>For R code hints you can provide a sequence of hints that reveal progressively more of the solution as desired by the user. To do this create a sequence of indexed hint chunks (e.g. “-hint-1”, “-hint-2,”-hint-3&quot;, etc.) for your exercise chunk. For example:</p>
<div id="exercisehints">

</div>
Expand Down Expand Up @@ -766,7 +773,7 @@ <h3>Checking Packages</h3>
</div>
<div id="exercise-caption" class="section level2">
<h2>Exercise Caption</h2>
<p>By default exercises are displayed with caption of “Code”. However, in some cases you may want either a custom per-chunk caption or a generic caption with a different connodation (e.g. “Exercise” or “Sandbox”). For example:</p>
<p>By default exercises are displayed with caption of “Code”. However, in some cases you may want either a custom per-chunk caption or a generic caption with a different connodation (e.g. “Exercise” or “Sandbox”). For example:</p>
<div id="exercisecaption">

</div>
Expand Down Expand Up @@ -853,7 +860,7 @@ <h2>Time Limits</h2>
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
Expand Down
3 changes: 1 addition & 2 deletions docs/formats.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Formats</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -501,7 +500,7 @@ <h2>Custom Formats</h2>
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
Expand Down
5 changes: 2 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Interactive Tutorials for R</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -582,7 +581,7 @@ <h3>Video Size</h3>
<div id="shiny-components" class="section level2">
<h2>Shiny Components</h2>
<p>The <strong>learnr</strong> package uses <code>runtime: shiny_prerendered</code> to turn regular R Markdown documents into live tutorials. Since tutorials are Shiny applications at their core, it’s also possible to add other forms of interactivity using Shiny (e.g. for teaching a statistical concept interactively).</p>
<p>The basic technique is to add a <code>context="server"</code> attribute to code chunks that are part of the Shiny server as opposed to UI definition. For example:</p>
<p>The basic technique is to add a <code>context=&quot;server&quot;</code> attribute to code chunks that are part of the Shiny server as opposed to UI definition. For example:</p>
<div id="shiny">

</div>
Expand Down Expand Up @@ -716,7 +715,7 @@ <h2>Publishing</h2>
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
Expand Down
9 changes: 4 additions & 5 deletions docs/publishing.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Publishing</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -392,7 +391,7 @@
<li>
<a href="https://github.com/rstudio/learnr">
<span class="fa fa-github"></span>

</a>
</li>
</ul>
Expand All @@ -417,15 +416,15 @@ <h2>R Package</h2>
learnr::run_tutorial(&quot;slidy&quot;, package = &quot;learnr&quot;)</code></pre>
<p>To bundle a tutorial into an R package and make it available for running via the <code>run_tutorial</code> function you should:</p>
<ol style="list-style-type: decimal">
<li><p>Create a <code>tutorials</code> directory within the <code>inst</code> sub-directory of your package and then create a directory for your tutorial there (e.g. <code>inst/tutorials/hello</code>, <code>inst/tutorials/slidy</code>, etc.).</p></li>
<li><p>Create a <code>tutorials</code> directory within the <code>inst</code> sub-directory of your package and then create a directory for your tutorial there (e.g. <code>inst/tutorials/hello</code>, <code>inst/tutorials/slidy</code>, etc.).</p></li>
<li><p>Add the <code>.Rmd</code> associated with your tutorial in that directory. (You may see a <code>..._files/</code> directory or a <code>.html</code> file that periodically get generated adjacent to your <code>.Rmd</code> tutorial. You can safely ignore, delete, or exclude these from your package and from version control. They are temporary artifacts produced while rendering the tutorial on your specific system and aren’t likely to be portable to other environments.)</p></li>
</ol>
<p>Once you’ve done this users can run your tutorial as follows (note they should be sure to install the <strong>learnr</strong> package before attempting to run the tutorial):</p>
<p>Users would then simply install learnr directly before running your tutorial, for example:</p>
<pre class="r"><code>install.packages(&quot;learnr&quot;)
learnr::run_tutorial(&quot;introduction&quot;, package = &quot;mypackage&quot;)</code></pre>
<div id="exercise-checkers" class="section level3 toc-ignore">
<h3 class="toc-ignore">Exercise Checkers</h3>
<h3>Exercise Checkers</h3>
<p>Note that if your tutorial performs <a href="exercises.html#checking-exercises">exercise checking</a> via an external package then you should be sure to add the package you use for checking as an <code>Imports</code> dependency of your package so it’s installed automatically along with your package.</p>
<p>Note that it’s likely that the <strong>learnr</strong> package will eventually include or depend on another package that provides checking functions. For the time being though explicit installation of external checking packages is a requirement.</p>
</div>
Expand Down Expand Up @@ -848,7 +847,7 @@ <h4>Custom Identifiers</h4>
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
Expand Down
3 changes: 1 addition & 2 deletions docs/questions.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<title>Questions</title>

<script src="site_libs/header-attrs-2.1.1/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
Expand Down Expand Up @@ -520,7 +519,7 @@ <h2>Groups of Questions</h2>
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
Expand Down
12 changes: 0 additions & 12 deletions docs/site_libs/header-attrs-2.1.1/header-attrs.js

This file was deleted.

3 changes: 3 additions & 0 deletions inst/tutorials/hello/learnr-folder-for-debug/exercise.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1 + 1
x <- 10

nischalshrestha marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions inst/tutorials/hello/learnr-folder-for-debug/exercise.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```{r }
# 1 + 1
x <- 10

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@





Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@