Returns information about the current tutorial. Ideally the function should
be evaluated in a Shiny context, i.e. in a chunk with option
context = "server"
. Note that the values of this function may change after
the tutorial is completely initialized. If called in a non-reactive context,
get_tutorial_info()
will return default values that will most likely
correspond to the current tutorial.
Usage
get_tutorial_info(
tutorial_path = NULL,
session = getDefaultReactiveDomain(),
...,
encoding = "UTF-8"
)
Arguments
- tutorial_path
Path to a tutorial
.Rmd
source file- session
The
session
object passed to function given toshinyServer.
Default isshiny::getDefaultReactiveDomain()
.- ...
Arguments passed on to
rmarkdown::render
output_format
The R Markdown output format to convert to. The option
"all"
will render all formats defined within the file. The option can be the name of a format (e.g."html_document"
) and that will render the document to that single format. One can also use a vector of format names to render to multiple formats. Alternatively, you can pass an output format object (e.g.html_document()
). If usingNULL
then the output format is the first one defined in the YAML frontmatter in the input file (this defaults to HTML if no format is specified there). If you pass an output format object tooutput_format
, the options specified in the YAML header or_output.yml
will be ignored and you must explicitly set all the options you want when you construct the object. If you pass a string, the output format will use the output parameters in the YAML header or_output.yml
.output_dir
The output directory for the rendered
output_file
. This allows for a choice of an alternate directory to which the output file should be written (the default output directory of that of the input file). If a path is provided with a filename inoutput_file
the directory specified here will take precedence. Please note that any directory path provided will create any necessary directories if they do not exist.output_options
List of output options that can override the options specified in metadata (e.g. could be used to force
self_contained
ormathjax = "local"
). Note that this is only valid when the output format is read from metadata (i.e. not a custom format object passed tooutput_format
).output_yaml
Paths to YAML files specifying output formats and their configurations. The first existing one is used. If none are found, then the function searches YAML files specified to the
output_yaml
top-level parameter in the YAML front matter, _output.yml or _output.yaml, and then uses the first existing one.intermediates_dir
Intermediate files directory. If a path is specified then intermediate files will be written to that path. If
NULL
, intermediate files are written to the same directory as the input file.knit_root_dir
The working directory in which to knit the document; uses knitr's
root.dir
knit option. IfNULL
then the behavior will follow the knitr default, which is to use the parent directory of the document.runtime
The runtime target for rendering. The
static
option produces output intended for static files;shiny
produces output suitable for use in a Shiny document (seerun
). The default,auto
, allows theruntime
target specified in the YAML metadata to take precedence, and renders for astatic
runtime target otherwise.clean
Using
TRUE
will clean intermediate files that are created during rendering.params
A list of named parameters that override custom params specified within the YAML front-matter (e.g. specifying a dataset to read or a date range to confine output to). Pass
"ask"
to start an application that helps guide parameter configuration.knit_meta
(This option is reserved for expert use.) Metadata generated by knitr.
envir
The environment in which the code chunks are to be evaluated during knitting (can use
new.env()
to guarantee an empty new environment).run_pandoc
An option for whether to run pandoc to convert Markdown output.
quiet
An option to suppress printing during rendering from knitr, pandoc command line and others. To only suppress printing of the last "Output created: " message, you can set
rmarkdown.render.message
toFALSE
- encoding
Ignored. The encoding is always assumed to be UTF-8.
Value
Returns an ordinary list with the following elements:
tutorial_id
: The ID of the tutorial, auto-generated or from thetutorial$id
key in the tutorial's YAML front matter.tutorial_version
: The tutorial's version, auto-generated or from thetutorial$version
key in the tutorial's YAML front matter.items
: A data frame with columnsorder
,label
,type
anddata
describing the items (questions and exercises) in the tutorial. This item is only available in the running tutorial, not during the static pre-render step.user_id
: The current user.learnr_version
: The current version of the running learnr package.language
: The current language of the tutorial, either as chosen by the user or as specified in thelanguage
item of the YAML front matter.
Examples
if (rmarkdown::pandoc_available("1.4")) {
tutorial_rmd <- local({
# Use a temp copy of "Hello learnr" tutorial for this example
src <- system.file(
"tutorials", "hello", "hello.Rmd", package = "learnr"
)
dest <- tempfile(fileext = ".Rmd")
file.copy(src, dest)
dest
})
# ---- This is the example! ------------ #
info <- get_tutorial_info(tutorial_rmd)
# -------------------------------------- #
# clean up the temporary Rmd used in this example
unlink(tutorial_rmd)
# This is the result of the example
info
}
#> $tutorial_id
#> [1] "/tmp/Rtmpuo6a0c"
#>
#> $tutorial_version
#> [1] "1.0"
#>
#> $items
#> # A tibble: 1 × 4
#> order label type data
#> <int> <chr> <chr> <list>
#> 1 1 addition exercise <r>
#>
#> $user_id
#> [1] "runner"
#>
#> $learnr_version
#> [1] "0.11.5"
#>
#> $language
#> [1] "en"
#>