View source: R/mock_exercise.R
mock_exercise | R Documentation |
Creates an interactive exercise object that can be used in tests without having to create a learnr tutorial.
mock_exercise(
user_code = "1 + 1",
label = "ex",
chunks = list(),
engine = "r",
global_setup = NULL,
setup_label = NULL,
solution_code = NULL,
code_check = NULL,
error_check = NULL,
check = NULL,
tests = NULL,
exercise.checker = NULL,
exercise.error.check.code = NULL,
exercise.df_print = "default",
exercise.warn_invisible = TRUE,
exercise.timelimit = 10,
fig.height = 4,
fig.width = 6.5,
fig.retina = 2,
version = current_exercise_version,
...
)
mock_chunk(label, code, exercise = FALSE, engine = "r", ...)
user_code, solution_code, global_setup |
The user, solution, and global setup code, as strings. |
label |
The label of the exercise. |
chunks |
A list of chunks to use for the exercise. Use |
engine |
The knitr language engine used by the exercise, equivalent to
the engine used for the chunk with |
setup_label |
The label of the chunk that contains the setup code. The
chunk itself should be among the list of chunks provided to the |
check, code_check, error_check |
The checking code, as a string, that
would typically be provided in the |
exercise.checker |
The exercise checker function, as a string. By
default, a debug exercise checker is set but will only be used if any of
|
exercise.error.check.code |
The default code used for |
exercise.df_print, exercise.warn_invisible, exercise.timelimit, fig.height, fig.width, fig.retina |
Common exercise chunk options. |
version |
The exercise version to emulate, by default |
... |
Additional chunk options as if there were included in the exercise chunk. |
code |
In |
exercise |
In |
An exercise object.
mock_exercise()
: Create a learnr exercise object
mock_chunk()
: Create a mock exercise-supporting chunk
mock_exercise(
user_code = "1 + 1",
solution_code = "2 + 2",
label = "two-plus-two"
)
# Global Setup
mock_exercise(
user_code = 'storms %>% filter(name = "Roxanne")',
solution_code = 'storms %>% filter(name == "Roxanne")',
global_setup = 'library(learnr)\nlibrary(dplyr)',
label = "filter-storms"
)
# Chained setup chunks
mock_exercise(
user_code = "roxanne",
solution_code = "roxanne %>%
group_by(year, month, day) %>%
summarize(wind = mean(wind))",
chunks = list(
mock_chunk(
label = "prep-roxanne",
code = 'roxanne <- storms %>% filter(name == "Roxanne")'
)
),
setup_label = "prep-roxanne",
global_setup = "library(learnr)\nlibrary(dplyr)"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.