tutorial::go_interactive()

You can use the tutorial package to convert static code chunks into 'fiddles', i.e. editors where people can experiment with your code. If you specify the ex and type properties, tutorial knows what to do:

a <- 2
b <- 3

a + b

You can also create interactive exercises right inside your R Markdown document. Suppose you want to explain people how variable assignment works in R. Create an exercise with a certain identifier, create_a in this case. Then, in different R code chunks, specify the elements of the exercise by setting the type inside the code chunk options.

b <- 5
# Create a variable a, equal to 5


# Print out a
# Create a variable a, equal to 5
a <- 5

# Print out a
a
test_object("a")
test_output_contains("a", incorrect_msg = "Make sure to print `a`.")
success_msg("Great!")


datacamp/tutorial documentation built on Nov. 2, 2022, 9:02 p.m.