Description Usage Arguments Value Examples
When I teach, I like to have a completed solution made first (so I know it works) and then modify this for students to fill in. It could be simple matters of filling in a function name or supplying an argument or it could be writing a complex series of functions. This requires manual deletion or changing of lines each time the solution file is changed. With this function, anything with the answerstring in it will be converted to the hidestring in the output (which could then be written to an exercise file). I sometimes insert stop functions, as well, to keep students from charging forward without thinking – they have to do what it says at this this point. This can also be included.
1 2 3 | ConvertSolution(x, answerstring = "# Answer",
hidestring = "____add answer___", stopstring = "# Stop and think: ",
collapsemany = TRUE)
|
x |
The vector of input strings (representing one line each) |
answerstring |
The tag indicating lines to convert to hide |
hidestring |
What to replace the answer lines with |
stopstring |
The tag indicating what to prompt user to do |
collapsemany |
If you have multiple answer strings in order, collapse |
The vector of transformed strings
1 2 3 4 5 | input <- c("# Count the number of tips", "phy <- ape::rcoal(15)",
"print(Ntip(phy)) # Answer",
"# Stop and think: How can you know this answer is correct?")
output <- ConvertSolution(input)
print(output)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.