ConvertSolution: Converts lines containing certain strings to other lines

Description Usage Arguments Value Examples

Description

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.

Usage

1
2
3
ConvertSolution(x, answerstring = "# Answer",
  hidestring = "____add answer___", stopstring = "# Stop and think: ",
  collapsemany = TRUE)

Arguments

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

Value

The vector of transformed strings

Examples

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)

bomeara/ConvertSolution documentation built on May 12, 2019, 11:33 p.m.