Lesson 3 of 17 · Week 02 · Thu Oct 1
Seeking Help
Questions
- How can I get help in R without being handed the answer?
- How do I read a help page and an error message?
- How do I find a function when I don't know its name?
Objectives
- Open and read a help page, starting from its Arguments and Examples sections.
- Search for functions by topic with
??andapropos(). - Read an error message and follow a routine to get unstuck.
- Explain why this course doesn't use generative AI as a help source at this stage.
Build paths, not just answers
When you're stuck, the quickest fix is to find someone (or something) that hands you working code. It works today, and it doesn't help next week. This lesson is about a slower habit that pays off quickly: building paths in your brain from a problem to R's own sources of information.
Each time you read the help page, read the error message, try something small, and compare what happened with what you expected, you strengthen a path you can use again, without anyone's help. That is what fluency in a programming language is: knowing where to look and how to read what you find, not memorising functions.
Adapted from Software Carpentry's “Seeking Help” episode (CC BY 4.0, The Carpentries). Text, examples and exercises have been rewritten for this course.
Why not generative AI (yet)
For now, don't use ChatGPT, Copilot, Claude or similar tools as a help source in this course. This isn't because they're useless. It's because of where you are in learning R:
- You can't check their answers yet. These tools often produce code that looks right but uses the wrong argument, invents a function, or quietly answers a slightly different question. Spotting that takes exactly the reading skills this lesson builds.
- They skip the part that makes you learn. Getting to the answer through the help page and the error message is the practice itself. Pasting a generated answer gets the exercise done but skips the learning.
- You'll use them better later. People who can read documentation and errors ask AI tools sharper questions and catch their mistakes. We'll come back to this once you have that foundation.
Reading a help page
Every function has a help page. In Positron's console type ?median or help("median"); the page
opens in the Help pane. They all share the same layout:
- Description: what the function does.
- Usage: how to call it, with each argument's default value (
median(x, na.rm = FALSE, ...)). - Arguments: what each argument means and what type it expects. Read this section first.
- Value: what the function returns.
- See Also: related functions. Often this is where you find the function you actually needed.
- Examples: runnable code.
example(median)runs them all. Often the fastest way in.
Operators have help pages too; put them in quotes: ?"%%", ?"[". Many packages also ship
longer tutorials called vignettes: browseVignettes("dplyr").
When you don't know the function's name
??"standard deviation"(same ashelp.search()) searches the titles and descriptions of every installed help page.apropos("mean")lists every function whose name containsmean.- The See Also section of a related function's help page.
- A web search with “R” plus what you want to do, or the exact error text in quotes. Prefer the official docs, Stack Overflow answers with explanations, and the Posit Community forum.
Reading error messages
An error message has two parts: where (Error in log(x) :, the call that failed) and what
(non-numeric argument to mathematical function). The ones you'll see most:
| Message | Usually means |
|---|---|
object 'x' not found | Typo, wrong capitalisation, or you never ran the line that creates x. |
could not find function "x" | Typo, or the package that has x isn't loaded with library(). |
unexpected symbol / unexpected ')' | A missing comma, bracket or quote on that line. |
non-numeric argument to ... | You gave text (maybe numbers stored as text) to something that needs numbers. |
A routine when you're stuck: (1) read the whole message; (2) re-read the line it points to; (3) open the
help page of the function in the message; (4) try a tiny example that reproduces the problem; (5) search the exact
message; (6) ask a classmate or instructor, bringing your tiny example and the output of sessionInfo().
Exercises
Each exercise gives you up to 10 checked attempts. Use Run as many times as you like to experiment first, then click Check answer when you're ready. Your exercises use numbers/subsets unique to you, so answers won't match a classmate's exactly.
Exercise 1 — Predict the type
0 / 10 attempts usedRead the help page for c in Positron (?c), especially what it says about combining values of
different types. Click Run to print four calls to c() (different for every student).
Predict first what type of vector each one creates, then store your predictions, in order, in a character
vector predicted using the names typeof() reports: "logical", "integer",
"double" or "character". Check yourself with typeof() before you submit.
Exercise 2 — sep or collapse?
0 / 10 attempts usedRead ?paste and find the difference between its sep and collapse arguments.
Then, using first and last (click Run to see them), create:
full: a character vector with one element per person, like"Ana_Rojas"(first and last joined by an underscore), androster: a single string with all the full names joined by" | ", like"Ana_Rojas | Kofi_Mensah".
Exercise 3 — Find the right reader
0 / 10 attempts usedTwo files are in this exercise's data/ folder. Both have columns separated by tabs
("\t"), but they write decimals differently:
data/plots_dot.txtuses a period, like12.5;data/plots_comma.txtuses a comma, like12,5(common in Latin America and Europe).
Use ??"read table" or ?read.table in Positron to find functions (and arguments) that read such
files. Read them into plots_dot and plots_comma so that the height column is
numeric in both. Peek first with readLines("data/plots_comma.txt").
Key Points
?nameopens a help page; read Arguments and run the Examples.??"topic"andapropos()find functions when you don't know the name.- Read the whole error message: it says where the problem is and what went wrong.
- Getting to an answer yourself (help, error, try, compare) is the skill; skipping it with AI tools skips the learning.
Proof of completion
Once you've attempted every exercise above, download a PDF summary of your work on this lesson — your name, the exercises you passed, attempt counts, timing, and your final code for each.