Lesson 3 of 17 · Week 02 · Thu Oct 1

Seeking Help

Questions

Objectives

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:

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:

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

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:

MessageUsually means
object 'x' not foundTypo, 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 used

Read 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.

Pasting isn't accepted here — please type your answer so it reflects your own work.

      

Exercise 2 — sep or collapse?

0 / 10 attempts used

Read ?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), and
  • roster: a single string with all the full names joined by " | ", like "Ana_Rojas | Kofi_Mensah".
Pasting isn't accepted here — please type your answer so it reflects your own work.

      

Exercise 3 — Find the right reader

0 / 10 attempts used

Two files are in this exercise's data/ folder. Both have columns separated by tabs ("\t"), but they write decimals differently:

  • data/plots_dot.txt uses a period, like 12.5;
  • data/plots_comma.txt uses a comma, like 12,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").

Pasting isn't accepted here — please type your answer so it reflects your own work.

      

Key Points

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.