Package: rmdex
QuickstartThe main things this library can do are:generate an exercise notebook and a solution notebook from a template
notebook, given some markup in the comments of the template notebook, andcheck mark totals specified in the comments, to make sure they add up
correctly.The utility expects the comments incode cellsto have some extra markup to
tell it what to do.It is equally happy processingR notebooksinRMarkdownformat, orJupyternotebooks saved as RMarkdown, probably usingJupytext.  You can see
examples of use on Jupyter notebooks inhttps://github.com/matthew-brett/cfd2019/tree/master/_ok_exercises.The comment notation is as follows:An exercise cell (Jupyter) or chunk (R notebook) is any cell / chunk with an
comment starting#-(an exercise comment) or starting#<-(see
below). Rmdex will only modify exercise cells / chunks in the output exercise
and solution.Anexercise commentis any comment beginning#-.  These pass
unmodified to the exercise and solution notebooks.Anexercise insertion commentis any comment beginning#<-followed
by a space. The text following will be a line that should not go in the
solution, but should go in the exercise.  It allows the template to suggest
code to the user, that will not appear in the solution. The code after this
mark need not be valid syntax.Aboth-section markeris a line consisting of#<-followed
immediately by a new line character. This indicates that all subsequent
lines, up to the next#<-line (both-section marker), should go into the
exercise and the solution.Aboth-line markeris a line consisting of#<--followed immediately
by a new line character.  The next line goes into the solution and the
exercise.If there is any line starting#<-and followed by anything other than
space, a new line, or a-, this is an error.Any other code lines, including ordinary comments beginning#, get
stripped from the exercise.  They do appear in the solution.Amarks commentis aexercise commentof form#- 5 marks / 100 (total 10 marks so far)where 5 is the marks for this cell, 100 is the total for
the whole exercise, and 10 is the total marks if all answers are correct up
to this point (including this cell).  You can use the--check-marksoption to the mainrmdexutility to check the consistency of these
numbers (see below).For example, the template may have a cell like this:```{r}
#- Here you will do a simple assignment.
#- More description of the assignment.
#- 5 marks / 100 (total 10 marks so far).
# This comment gets stripped from the exercise version of the cell.
# Also this one.  The next line adds the text after #<- to the exercise.
#<- my_variable = ...
# This comment and the next code line do not appear in the exercise.
my_variable = 10
#<-
# This comment does appear in the exercise, as well as the following code.
another_variable = 11
print("Something")
#<-
#<--
# This line follows the both-line marker, and appears in the exercise.
# This line does not.
# Starting at the previous line, we resume normal service.  This and
# the next line of comments do not appear in the exercise.
#
# The following marker causes everything to the end of the cell/chunk
# to appear in both exercise and solution:
#<->
print('This line appears in the exercise and solution')
print('as does this line')
```The template cell above results in the following in the exercise version:```{r}
#- Here you will do a simple assignment.
#- More description of the assignment.
#- 5 marks / 100 (total 10 marks so far).
my_variable = ...
# This comment does appear in the exercise, as well as the following code.
another_variable = 11
print("Something")
# This line follows the both-line marker, and appears in the exercise.
print('This line appears in the exercise and solution')
print('as does this line')
```The solution will have:```{r}
#- Here you will do a simple assignment.
#- More description of the assignment.
#- 5 marks / 100 (total 10 marks so far).
# This comment gets stripped from the exercise version of the cell.
# Also this one.  The next line adds the text after #<- to the exercise.
# This comment and the next code line do not appear in the exercise.
my_variable = 10
# This comment does appear in the exercise, as well as the following code.
another_variable = 11
print("Something")
# This line follows the both-line marker, and appears in the exercise.
# This line does not.
# Starting at the previous line, we resume normal service.  This and
# the next line of comments do not appear in the exercise.
#
# The following marker causes everything to the end of the cell/chunk
# to appear in both exercise and solution:
print('This line appears in the exercise and solution')
print('as does this line')
```The scriptrmdexreads the templates, checks the mark totals (with the
option--check-marks), and generates the exercise.  It can also generate the solution.  Here are some examples of use:#Generatetheexercisefromthetemplate.rmdex template_notebook.Rmd exercise_notebook.Rmd#Generatetheexerciseandsolutionfromthetemplate.rmdex template_notebook.Rmd exercise_notebook.Rmd solution_notebook.Rmd#Checkthemarkstotalintheexercise,butdonotwritetheexercise.rmdex --check-marks template_notebook.Rmd#Checkthemarkstotalintheexercise,andwritetheexercise.rmdex --check-marks template_notebook.Rmd exercise_notebook.Rmd#Writethesolutiononly.rmdex template_notebook.Rmd _ solution_notebook.RmdInstallationpip install rmdexCodeSeehttps://github.com/matthew-brett/rmdexReleased under the BSD two-clause license - see the fileLICENSEin the
source distribution.travis-cikindly tests the code
automatically under Python versions 3.6 through 3.8.The latest released version is athttps://pypi.python.org/pypi/rmdexTestsInstallrmdex;Install thepytesttesting framework:pip install pytestRun the tests with:pytest rmdexSupportPlease put up issues on thermdex issue tracker.