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:

eyJzYW1wbGUiOiJhIDwtIDJcbmIgPC0gM1xuXG5hICsgYiJ9

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.

eyJwcmVfZXhlcmNpc2VfY29kZSI6IiMgVGhpcyBjb2RlIGlzIGF2YWlsYWJsZSBpbiB0aGUgd29ya3NwYWNlIHdoZW4gdGhlIHNlc3Npb24gaW5pdGlhbGl6ZXNcbmIgPC0gNSIsInNhbXBsZSI6IiMgQ3JlYXRlIGEgdmFyaWFibGUgYSwgZXF1YWwgdG8gNVxuXG5cbiMgUHJpbnQgb3V0IGEiLCJzb2x1dGlvbiI6IiMgQ3JlYXRlIGEgdmFyaWFibGUgYSwgZXF1YWwgdG8gNVxuYSA8LSA1XG5cbiMgUHJpbnQgb3V0IGFcbmEiLCJzY3QiOiJ0ZXN0X29iamVjdChcImFcIilcbnRlc3Rfb3V0cHV0X2NvbnRhaW5zKFwiYVwiLCBpbmNvcnJlY3RfbXNnID0gXCJNYWtlIHN1cmUgdG8gcHJpbnQgYGFgXCIpXG5zdWNjZXNzX21zZyhcIkdyZWF0IVwiKSJ9