The Little R'er

a question-based introduction to R

What is this?

The Little R'er is an educational resource in the style of the classic book The Little Schemer. Chapters are presented as a series of questions. To read the answer to each question, click the white space in the right column. Like so:

Is it true that l is the best animal when l is equal to



because kittens are the best animal.

There are also summary boxes, which can likewise be viewed by clicking the content:

Summary: Kittens

Kittens are the best!

This project is nowhere near as elegant as The Little Schemer. That's mostly my fault, but it's at least a little bit R's fault.

Who wrote this, and why?

My name's Shauna. I started this project to help me learn R, so I have likely gotten things wrong. Suggestions and corrections are very welcome. You can view the project's repository here and issue tracker here. Feel free to make pull requests as well.

Where's the table of contents?

Right here!

What resources have you used?

I've used the following resources while making this project, in no particular order:

Anything else?

While working on this project, I discovered a few things R does that are worth a warning.

  • Recycling: If you ask R to do vector arithmetic with vectors of different lengths, R will recycle the shorter of the two vectors until the length matches. If the longer vector is a multiple of the shorter vector, it will do so silently, without telling you. If the longer vector is not a multiple, it will give a warning or not work at all. Keep an eye out for situations where R might be silently recycling your data without you realizing it.
  • Type Coercion: Atomic vectors and matrices in R must have objects all of the same type. This means that R will sometimes silently convert your data from one type to another. This is covered in chapters 1 and 2, but is worth stating explicitly. As Hadley Wickham puts it: "All elements of an atomic vector must be the same type, so when you attempt to combine different types they will be coerced to the most flexible type. Types from least to most flexible are: logical, integer, double, and character." Because matricies can only have different types when created by shaping a list, they're much simpler: any matrix made from a list is a matrix of type lists. This means that to access the value in row 1, column 1 of a matrix formed out of a list, you need to use the syntax matrix[[1,1]] rather than matrix[1,1] (which gets the list containing the value).