Compute things with R functions

What is a function in R?

say(), c(), dim(), str(), read_csv() are all examples of functions.

Functions perform specific operations / transformations in computer programming.

They can have inputs and outputs. For example, dim() takes some data you have stored in R as its input, and gives the dimensions of the data as its output.

Get help with functions

In R, functions come with help pages, where you can see information about the various inputs and outputs, and examples of how to use them.

In the console, type ?dim (or ?dim() will work too) and press Enter.
The bottom-right pane (where things like plots are also shown), should switch to the Help tab, and open the documentation page for the dim() function!

Note

Why did we ask you to write this bit in the console, whereas previously we’ve been writing stuff in the RMarkdown document in the editor?

When writing an R script, the aim at the end is to have a clear and minimal document which we and other interested readers can use to reproduce our analyses. But the reader doesn’t need to see that we’re looking up how to use some function, just like they don’t need to know that we might look up a word in the dictionary before using it.