A little bit dotty

Defensive R Programming

Dr. Colin Gillespie

Jumping Rivers

The full stop

In R, the full stop has a very special meaning

  • It is the mechanism that is used in S3 OOP
  • When you call the summary() function
    • R looks for the function summary.class_name
Defensive R Programming

Example: the summary() function

When you call

m <- lm(mpg ~ disp, data = mtcars)
class(m)
#[1] "lm"
Defensive R Programming

Example: the summary() function

So when you call

summary(m)

you end up calling

summary.lm(m)

The key point here, is that the full stop is very important

Defensive R Programming

One bit of advice

  • There are few R rules that everyone agrees on
  • But everyone agrees that you should avoid . in variable names
  • It just prevents confusion
Defensive R Programming

The final stop

Defensive R Programming

Preparing Video For Download...