Hi all,
I am finding the R code answer type very useful. But I have hit one 'feature' that I would like some advice on.
In the 'Correct answer' box, I often need to use curly braces. E.g. when the correct code involves a for loop or an if...else. If I put the correct R code straight into the Correct answer box I get an error, because it thinks that inside the curly braces should be variables, and these are missing. (If I define the variables, it tries to evaluate the expression, which is also not the right thing to do here.)
Example: this is not accepted as a Correct answer:
s <- 0
for (j in 1:n) {
s <- s + (2*j-1)
}
My workaround is to define the entire model code answer as a safe string in a variable. But this is quite cumbersome when the model answer is many lines long. Example: a variable defined as follows is accepted and will print fine.
safe("s <- 0 \nfor (j in 1:n) {\n s <- s + (2*j-1)\n}")
I hit the same problem in the Prompt text box for each question, although in that case it seems to work ok as long as I include line breaks in exactly the right places.
Is there an alternative, e.g. some way to escape the usual function of curly braces (e.g. \{ ... \}) inside the Correct answer nd Prompt boxes?
Keep up the good work!
All the best,
Simon