Long-form tutorial which includes narrative, figures, videos, exercises, and questions.
Usage
tutorial(
fig_width = 6.5,
fig_height = 4,
fig_retina = 2,
fig_caption = TRUE,
progressive = FALSE,
allow_skip = FALSE,
dev = "png",
df_print = "paged",
smart = TRUE,
theme = "rstudio",
highlight = "textmate",
ace_theme = "textmate",
mathjax = "default",
extra_dependencies = NULL,
css = NULL,
includes = NULL,
md_extensions = NULL,
pandoc_args = NULL,
language = "en",
lib_dir = NULL,
...
)
Arguments
- fig_width
Default width (in inches) for figures
- fig_height
Default height (in inches) for figures
- fig_retina
Scaling to perform for retina displays (defaults to 2, which currently works for all widely used retina displays). Set to
NULL
to prevent retina scaling. Note that this will always beNULL
whenkeep_md
is specified (this is becausefig_retina
relies on outputting HTML directly into the markdown document).- fig_caption
TRUE
to render figures with captions- progressive
Display sub-topics progressively (i.e. wait until previous topics are either completed or skipped before displaying subsequent topics).
- allow_skip
Allow users to skip sub-topics (especially useful when
progressive
isTRUE
).- dev
Graphics device to use for figure output (defaults to png)
- df_print
Method to be used for printing data frames. Valid values include "default", "kable", "tibble", and "paged". The "default" method uses a corresponding S3 method of
print
, typicallyprint.data.frame
. The "kable" method uses theknitr::kable
function. The "tibble" method uses the tibble package to print a summary of the data frame. The "paged" method creates a paginated HTML table (note that this method is only valid for formats that produce HTML). In addition to the named methods you can also pass an arbitrary function to be used for printing data frames. You can disable thedf_print
behavior entirely by setting the optionrmarkdown.df_print
toFALSE
. See Data frame printing section in bookdown book for examples.- smart
Produce typographically correct output, converting straight quotes to curly quotes,
---
to em-dashes,--
to en-dashes, and...
to ellipses. Deprecated in rmarkdown v2.2.0.- theme
Visual theme ("rstudio", default", "cerulean", "journal", "flatly", "readable", "spacelab", "united", "cosmo", "lumen", "paper", "sandstone", "simplex", or "yeti").
- highlight
Syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "textmate". Pass ‘NULL’ to prevent syntax highlighting. Note, this value only pertains to standard rmarkdown code, not the Ace editor highlighting.
- ace_theme
Ace theme supplied to the ace code editor for all exercises. See
learnr:::ACE_THEMES
for a list of possible values. Defaults to"textmate"
.- mathjax
Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is copied into the output directory). You can pass an alternate URL or pass
NULL
to exclude MathJax entirely.- extra_dependencies
Extra dependencies as a list of the
html_dependency
class objects typically generated byhtmltools:htmlDependency()
.- css
CSS and/or Sass files to include. Files with an extension of .sass or .scss are compiled to CSS via
sass::sass()
. Also, iftheme
is abslib::bs_theme()
object, Sass code may reference the relevant Bootstrap Sass variables, functions, mixins, etc.- includes
Named list of additional content to include within the document (typically created using the
includes
function).- md_extensions
Markdown extensions to be added or removed from the default definition of R Markdown. See the
rmarkdown_format
for additional details.- pandoc_args
Additional command line options to pass to pandoc
- language
Language or custom text of the UI elements. See
vignette("multilang", package = "learnr")
for more information about available options and formatting- lib_dir
Directory to copy dependent HTML libraries (e.g. jquery, bootstrap, etc.) into. By default this will be the name of the document with
_files
appended to it.- ...
Forward parameters to html_document
Value
An rmarkdown::output_format()
for learnr tutorials.
Examples
tutorial()
#> $knitr
#> $knitr$opts_chunk
#> $knitr$opts_chunk$dev
#> [1] "png"
#>
#> $knitr$opts_chunk$dpi
#> [1] 96
#>
#> $knitr$opts_chunk$fig.width
#> [1] 6.5
#>
#> $knitr$opts_chunk$fig.height
#> [1] 4
#>
#> $knitr$opts_chunk$fig.retina
#> [1] 2
#>
#> $knitr$opts_chunk$tutorial
#> [1] TRUE
#>
#> $knitr$opts_chunk$max.print
#> [1] 1000
#>
#>
#> $knitr$opts_knit
#> NULL
#>
#> $knitr$knit_hooks
#> $knitr$knit_hooks$tutorial
#> function (before, options, envir)
#> {
#> if (!before) {
#> .learnr_messages$flush()
#> }
#> exercise_wrapper_div <- function(suffix = NULL, extra_html = NULL) {
#> if (before) {
#> if (!is.null(suffix))
#> suffix <- paste0("-", suffix)
#> class <- paste0("exercise", suffix)
#> lines <- ifelse(is.numeric(options$exercise.lines),
#> options$exercise.lines, 0)
#> completion <- as.numeric(options$exercise.completion %||%
#> 1 > 0)
#> diagnostics <- as.numeric(options$exercise.diagnostics %||%
#> 1 > 0)
#> startover <- as.numeric(options$exercise.startover %||%
#> 1 > 0)
#> paste0("<div class=\"tutorial-", class, "\" data-label=\"",
#> options$label, "\" data-completion=\"", completion,
#> "\" data-diagnostics=\"", diagnostics, "\" data-startover=\"",
#> startover, "\" data-lines=\"", lines, "\" data-pipe=\"",
#> htmltools::htmlEscape(exercise_option_pipe(options)),
#> "\">")
#> }
#> else {
#> c(extra_html, "</div>")
#> }
#> }
#> if (is_exercise_chunk(options)) {
#> extra_html <- NULL
#> if (before) {
#> verify_tutorial_chunk_label()
#> knitr::knit_meta_add(list(list(ace_html_dependency()),
#> list(clipboardjs_html_dependency())))
#> exercise_server_chunk(options$label)
#> }
#> else {
#> options$engine <- knitr_engine(options$engine)
#> options$exercise.df_print <- options$exercise.df_print %||%
#> knitr::opts_knit$get("rmarkdown.df_print") %||%
#> "default"
#> options$exercise.checker <- dput_to_string(options$exercise.checker)
#> all_chunks <- get_all_chunks(options)
#> code_check_chunk <- get_knitr_chunk(paste0(options$label,
#> "-code-check"))
#> error_check_chunk <- get_knitr_chunk(paste0(options$label,
#> "-error-check"))
#> check_chunk <- get_knitr_chunk(paste0(options$label,
#> "-check"))
#> solution <- get_knitr_chunk(paste0(options$label,
#> "-solution"))
#> tests <- get_knitr_chunk(paste0(options$label, "-tests"))
#> class(options) <- NULL
#> all_setup_code <- NULL
#> if (length(all_chunks) > 1) {
#> all_setup_code <- paste0(vapply(all_chunks[-length(all_chunks)],
#> function(x) x$code, character(1)), collapse = "\n")
#> }
#> this_exercise <- structure(list(label = options[["label"]],
#> global_setup = get_setup_global_exercise(), setup = all_setup_code,
#> chunks = all_chunks, code_check = code_check_chunk,
#> error_check = error_check_chunk, check = check_chunk,
#> solution = solution, tests = tests, options = options[setdiff(names(options),
#> "tutorial")], engine = options$engine, version = current_exercise_version),
#> class = c(options$engine, "tutorial_exercise"))
#> rmarkdown::shiny_prerendered_chunk("server", sprintf("learnr:::store_exercise_cache(%s)",
#> dput_to_string(this_exercise)))
#> caption <- if (!is.null(options$exercise.cap)) {
#> as.character(options$exercise.cap)
#> }
#> else {
#> cap_engine <- knitr_engine(options$engine)
#> cap_engine_file <- system.file(file.path("internals",
#> "icons", paste0(cap_engine, ".svg")), package = "learnr")
#> if (file.exists(cap_engine_file)) {
#> as.character(htmltools::div(class = "tutorial_engine_icon",
#> htmltools::HTML(readLines(cap_engine_file))))
#> }
#> else {
#> cap_engine_val <- knitr_engine_caption(options[["engine"]])
#> i18n_span("text.enginecap", paste(cap_engine_val,
#> "Code"), opts = list(engine = cap_engine_val))
#> }
#> }
#> ui_options <- list(engine = options$engine, has_checker = (!is.null(check_chunk) ||
#> !is.null(code_check_chunk)), caption = as.character(caption))
#> extra_html <- c("<script type=\"application/json\" data-ui-opts=\"1\">",
#> jsonlite::toJSON(ui_options, auto_unbox = TRUE),
#> "</script>")
#> }
#> exercise_wrapper_div(extra_html = extra_html)
#> }
#> else if (is_exercise_support_chunk(options)) {
#> if (is_exercise_support_chunk(options, type = c("hint",
#> "hint-\\d+"))) {
#> exercise_wrapper_div(suffix = "support")
#> }
#> else if (is_exercise_support_chunk(options, type = "solution")) {
#> if (get_reveal_solution_option(options)) {
#> exercise_wrapper_div(suffix = "support")
#> }
#> }
#> }
#> }
#> <bytecode: 0x563506321fc0>
#> <environment: 0x563506ca4740>
#>
#>
#> $knitr$opts_hooks
#> $knitr$opts_hooks$tutorial
#> function (options)
#> {
#> options$label <- unname(options$label)
#> exercise_chunk <- is_exercise_chunk(options)
#> exercise_support_chunk <- is_exercise_support_chunk(options)
#> exercise_setup_chunk <- is_exercise_support_chunk(options,
#> type = "setup")
#> if ((exercise_chunk || exercise_support_chunk) && !is_shiny_prerendered_active()) {
#> stop("Tutorial exercises require the use of 'runtime: shiny_prerendered'",
#> call. = FALSE)
#> }
#> if (exercise_chunk && is_chunk_empty_or_mismatched_exercise(options)) {
#> ensure_knit_code_exists(options)
#> }
#> if (exercise_chunk) {
#> initialize_tutorial()
#> options$echo <- TRUE
#> options$include <- TRUE
#> options$highlight <- FALSE
#> options$comment <- NA
#> if (!is.null(options$exercise.eval))
#> options$eval <- options$exercise.eval
#> else options$eval <- FALSE
#> return(options)
#> }
#> if (exercise_support_chunk) {
#> options$echo <- TRUE
#> options$include <- TRUE
#> options$eval <- FALSE
#> options$highlight <- FALSE
#> }
#> if (is_exercise_support_chunk(options, type = c("code-check",
#> "error-check", "check", "tests"))) {
#> options$include <- FALSE
#> }
#> if (is_exercise_support_chunk(options, type = "check")) {
#> if (is.null(knitr::opts_chunk$get("exercise.checker"))) {
#> stop("An exercise check chunk exists ('", options$label,
#> "') but an ", "exercise checker function is not configured for this tutorial. ",
#> "Please use `tutorial_options()` to define an `exercise.checker`.")
#> }
#> }
#> if (is_exercise_support_chunk(options, type = "solution")) {
#> options$echo <- get_reveal_solution_option(options)
#> }
#> if (exercise_setup_chunk) {
#> exercise_eval <- knitr::opts_chunk$get("exercise.eval")
#> if (is.null(exercise_eval))
#> exercise_eval <- FALSE
#> labels <- exercise_chunks_for_setup_chunk(options$label)
#> if (grepl("-setup$", options$label))
#> labels <- c(labels, sub("-setup$", "", options$label))
#> labels <- paste0("\"", labels, "\"")
#> labels <- paste0("c(", paste(labels, collapse = ", "),
#> ")")
#> label_query <- paste0("knitr::all_labels(label %in% ",
#> labels, ", ", "identical(exercise.eval, ", !exercise_eval,
#> "))")
#> default_reversed <- length(eval(parse(text = label_query))) >
#> 0
#> if (default_reversed)
#> exercise_eval <- !exercise_eval
#> options$eval <- exercise_eval
#> options$echo <- FALSE
#> }
#> if (is_exercise_support_chunk(options, type = "error-check") &&
#> is.null(get_knitr_chunk(sub("-error", "", options$label)))) {
#> stop("Exercise '", sub("-error-check", "", options$label),
#> "': ", "a *-check chunk is required when using an *-error-check chunk, but",
#> " '", sub("-error", "", options$label), "' was not found in the tutorial.",
#> call. = FALSE)
#> }
#> options
#> }
#> <bytecode: 0x56350631dc68>
#> <environment: 0x563506ca4740>
#>
#>
#> $knitr$opts_template
#> NULL
#>
#>
#> $pandoc
#> $pandoc$to
#> [1] "html4"
#>
#> $pandoc$from
#> [1] "markdown+autolink_bare_uris+tex_math_single_backslash"
#>
#> $pandoc$args
#> [1] "--embed-resources"
#> [2] "--standalone"
#> [3] "--variable"
#> [4] "bs3=TRUE"
#> [5] "--section-divs"
#> [6] "--template"
#> [7] "/home/runner/work/_temp/Library/rmarkdown/rmd/h/default.html"
#> [8] "--no-highlight"
#> [9] "--variable"
#> [10] "highlightjs=1"
#> [11] "--section-divs"
#> [12] "--reference-location=section"
#> [13] "--template"
#> [14] "/home/runner/work/_temp/Library/learnr/rmarkdown/templates/tutorial/resources/tutorial-format.htm"
#> [15] "--no-highlight"
#> [16] "--variable"
#> [17] "highlightjs=1"
#> [18] "--variable"
#> [19] "progressive=false"
#> [20] "--variable"
#> [21] "allow-skip=false"
#> [22] "--variable"
#> [23] "learnr-version=0.11.5"
#>
#> $pandoc$keep_tex
#> [1] FALSE
#>
#> $pandoc$latex_engine
#> [1] "pdflatex"
#>
#> $pandoc$ext
#> [1] ".html"
#>
#> $pandoc$convert_fun
#> NULL
#>
#> $pandoc$lua_filters
#> [1] "/home/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/pagebreak.lua"
#> [2] "/home/runner/work/_temp/Library/rmarkdown/rmarkdown/lua/latex-div.lua"
#>
#>
#> $keep_md
#> [1] FALSE
#>
#> $clean_supporting
#> [1] FALSE
#>
#> $df_print
#> [1] "paged"
#>
#> $pre_knit
#> function (...)
#> {
#> op(base(...), overlay(...))
#> }
#> <bytecode: 0x5635044dc4c8>
#> <environment: 0x5634fd7c9c48>
#>
#> $post_knit
#> function (...)
#> {
#> op(base(...), overlay(...))
#> }
#> <bytecode: 0x5635044dc4c8>
#> <environment: 0x563501865068>
#>
#> $pre_processor
#> function (...)
#> {
#> op(base(...), overlay(...))
#> }
#> <bytecode: 0x5635044dc4c8>
#> <environment: 0x563501e18628>
#>
#> $intermediates_generator
#> function (original_input, intermediates_dir)
#> {
#> copy_render_intermediates(original_input, intermediates_dir,
#> !self_contained)
#> }
#> <bytecode: 0x56350440de78>
#> <environment: 0x563505009048>
#>
#> $post_processor
#> function (metadata, input_file, output_file, ...)
#> {
#> original_output_file <- output_file
#> output_file <- overlay(metadata, input_file, output_file,
#> ...)
#> if (!is.null(attr(output_file, "post_process_original")))
#> base(metadata, input_file, original_output_file, ...)
#> base(metadata, input_file, output_file, ...)
#> }
#> <bytecode: 0x5635044e29f0>
#> <environment: 0x563506396d68>
#>
#> $file_scope
#> NULL
#>
#> $on_exit
#> function ()
#> {
#> if (is.function(base))
#> base()
#> if (is.function(overlay))
#> overlay()
#> }
#> <bytecode: 0x5635044e6590>
#> <environment: 0x563506a291f0>
#>
#> attr(,"class")
#> [1] "rmarkdown_output_format"