Chapter 2 How R works

R is both a software and a language. There are just a few things that the user should be aware of to understand how R works that we can separate between these 2 aspects.

In this chapter:

  • R is a software
  • R is a language
  • Working with R: objects and workspace

2.1 R is a software

R is a software that:

  • should be installed on the computer prior to class (see section 1.1.)
  • has a basic set of capabilities that can be enhanced by adding packages
  • can be used as a computation engine by other software such as RStudio
  • is mostly run by commands entered with the keyboard

2.2 R is a language

As a language R has capabilities to:

  • use mathematical and logical operators
  • create and use variables with the assignment operator <-
  • recognizes and handles different data types including scalars, vectors (numerical, character, logical), matrices, data frames, and lists.
  • can create plots and graphics
  • import data from many file types, from text to databases or from the web
  • use built-in functions to carry out a specified task on the data or variables.
  • add new collections of R functions, data, and compiled code in a well-defined format in the form of additional packages.
  • provide a comprehensive built-in help system.

2.2.1 Classic R vs Tidyverse

The way R works with commands can be confusing for multiple reasons. Statements written in the original R language now called “Classic R” can be sometimes cumbersome and lacking in clarity. The newer set of pcakges that make upa “Suite” called Tidyverse has created a new set of language format that is more modular and often easier to understand.

After reviewing basic “Classic R” we’ll also review Tidyverse methods when working on datasets later on.

2.3 Working with R: objects and workspace

The workspace is a working environment where R will store and remember user-defined objects: vectors, matrices, data frames, lists, functions, variables etc. At the end of an R session, the user can save an image of the current workspace that is automatically reloaded the next time R is started.

Except for functions most of the user-defined objects are usually referred to as R objects as a way to designate them. An R object makes it easy for humans to designate its content which could be a single numerical value or a large table of data.

R objects are containers hodling data, variables, tables, etc.

Figure 2.1: R objects are containers hodling data, variables, tables, etc.

R tends to keep all data in the computer memory (RAM) which used to limit the ability to work on large datasets. However, there are now special packages and functions that can help with this aspect.

R holds workspace, objects in RAM.

Figure 2.2: R holds workspace, objects in RAM.