You have used R to open a door. Now you can design a door for someone else. Perhaps your puzzle involves snails in quadrats, fish lengths, bird nests, or plants in different habitats. Pick something you understand and help another student practise one useful idea.
For this coursework, your contribution is an R file containing your room. You can submit that file through Moodle. Your teacher will set the deadline, the number of rooms to submit, and the extra points available. A room does not need complicated code to be useful: a clear question and a working answer are a good starting point.
.R
file..R file to the coursework submission on
Moodle.The rest of this guide walks you through those four steps. You can use the same R and RStudio setup you use for practical classes.
In RStudio, choose File > New File > R Script.
Copy the following code into the script and save it. For example, a
student with number 19549 might name the file
19549_snail_room.R. Use your own number and a short name
for your topic. Keep the .R ending.
This is a complete example. First try it unchanged so you can see how it works; then make your own version for submission.
# Author: replace with your name
# Student number: replace with your student number
# Course topic: means of ecological counts
# Data source: invented counts for this teaching example
# Teacher's solution: mean(c(2, 4, 6)) gives 4 snails per quadrat
# Change the example into your own puzzle before submitting it.
library(escapeR)
my_room <- new_room(
id = "s19549a",
module = "Ecological summaries",
title = "The Snail Garden",
learning_goal = "Create a vector and calculate a mean.",
introduction = "A garden gate is locked. Three quadrat counts are written on its sign.",
challenge = "Three equal-area quadrats contain 2, 4, and 6 snails. Use R to calculate the mean number of snails per quadrat. Submit that mean.",
hints = c(
"The mean is the sum of the counts divided by the number of quadrats.",
"Use c() to put the three counts into a vector, then use mean().",
"Try mean(c(2, 4, 6))."
),
correct_result = 4,
success = "The gate opens. You can take your field notebook into the garden!",
failure = "Check that you included all three quadrats, then calculate their mean."
)
# This makes the room available for playing in this R session.
# replace = TRUE lets you source the file again after editing your own room.
register_rooms(my_room, replace = TRUE)You can also copy the supplied template into your working folder by running these lines in the Console:
Open my-room.R in RStudio and save your edited version
with your student number in its filename. If file.copy()
returns FALSE, check whether a file with that name already
exists and choose a new filename.
library(escapeR) makes the game’s tools available.
new_room(...) creates a room from the information between
its brackets. my_room <- gives the room an object name,
so R can refer to it later. The final register_rooms(...)
line makes the room available to play in the current R session.
Most of your editing will be ordinary text between quotation marks.
Lines beginning with # are comments: notes for you and your
teacher. R does not run them.
Choose the question first. Solve it yourself in R before writing the story. Here are a few manageable ideas:
Pick an idea related to something you have practised in class. Keep one main task per room. The challenge should give another student enough information to solve it without asking you for the data or guessing your intention.
Edit these parts of the template:
| Part | What to put there |
|---|---|
| Comments at the top | Your name, student number, course topic, data source, and worked R solution |
id |
A short code for your room, starting with a letter and at most 8 characters |
module |
The topic, such as "Probability" or
"Ecological summaries" |
title |
A short name for the room |
learning_goal |
One sentence saying what someone will practise |
introduction |
A short story explaining the locked door |
challenge |
The ecological question, its data, units, and the answer to submit |
hints |
Three clues, from a small nudge to a clear R suggestion |
correct_result |
The answer you calculated yourself |
success |
A message for someone who solves the puzzle |
failure |
A helpful message for someone who tries a wrong answer |
For an ID, you could use s followed by the last five
digits of your student number and a letter: s19549a, then
s19549b for a second room. Use your own number. Keep this
ID different from existing rooms; en01 to en25
already belong to the course. You can inspect existing IDs with
list_rooms().
In the example, the counts are 2, 4, and 6. Check their mean in the Console:
That is why the template says correct_result = 4. If you
change the counts, calculate the new answer and update
correct_result, the hints, and the worked solution in your
comments. Updating only the question leaves the lock checking the old
answer.
For a number, write the number without quotes:
correct_result = 4. For a word, use quotes:
correct_result = "wetland". Text answers ignore case and
spaces at the beginning or end.
If your question requests rounding, state it clearly, for example:
“Submit the mean in cm, rounded to two decimal places.” Calculate that
rounded answer with round(...) and put it in
correct_result. For this simple template, students should
submit the requested rounded value; the default numeric checker uses a
small numerical tolerance.
For a first room, put a few values directly in the challenge. Invented data are fine for a teaching puzzle: say they are invented in your comments. For real data, record their source and include any permission or licence information needed to share them.
If you need a separate data file, include it with the submission and
explain how to read it. Use a relative filename such as
"snails.csv" so your teacher can put the files in one
folder and run the example. Include units and explain what each column
represents. Small self-contained examples are easier to review and
reuse.
Save the script after editing. In the Console, run the following commands, using the actual name of your saved file:
source() runs the saved script. The second line starts a
new test game containing your one room. The room should appear on
screen.
If R cannot find the script, use RStudio’s Source
button with the script open, then run the escape(...) line
in the Console. This avoids having to type its location.
For the unchanged snail example, try these commands in order:
submit(5) # A wrong answer should leave the door locked.
hint() # The first clue should appear.
hint() # The second clue should appear.
hint() # The final clue should help you solve the task in R.
submit(4) # The correct answer should open the door.For your own puzzle, choose a wrong answer and your calculated
correct answer. For a word answer, use quotes, for example
submit("wetland").
After another edit, save and source the file again, then repeat the
test. replace = TRUE lets your newly edited definition
replace your own previously registered room with the same ID.
Registration lasts for the current R session; source your file again
after restarting R.
new_room(...) and
between hints.If a sentence contains a quote, use single quotes inside the
sentence, as in "The sign says 'Count the snails'.". Change
one part at a time and rerun the script; it is easier to find a small
mistake that way.
Ask a classmate to play the room without seeing your solution. If they cannot tell which quantity or units to submit, clarify the question before submitting.
Upload your saved .R file to the coursework submission
indicated by your teacher. For a self-contained room, that one file is
enough. Your teacher can read the code, source the file, and play your
room.
Before uploading, check:
You can also write a short note in Moodle describing what the room teaches and anything you would like feedback on. Follow the assignment’s instructions for any additional explanation or reflection.
If you already use GitHub and want the room considered for inclusion in the package, the contribution route is a pull request: a proposal that the maintainer can review before adding your changes.
The package’s existing room-authoring guide explains how to put rooms into a pack, add that pack to the package catalogue, and check that it works. Open it in R with:
Use that route when you want to prepare a package contribution. The
Moodle .R file route is sufficient for submitting this
coursework; your teacher can help adapt a submitted room into a package
contribution later. Follow the course’s submission instructions so your
contribution can be matched to you for assessment.