Welcome to a short course which will introduce you to some more of the R programming language. The aim of this workshop is to build on Beginning R, and to then introduce enough of the language that you will be ready to learn how to use R to perform data analysis and visualisation (e.g. as will be covered in Introduction to Data Analysis with R).
You can jump ahead to any chapter:
%>% Forward pipe - walkthrough videoFor the purposes of this workshop we will be using RStudio. If you haven’t installed and got RStudio working, then please follow the instructions in the Beginning R workshop.
Start RStudio on your computer. This should open a window that looks something like this:
In Beginning R we set RStudio to have a text editor and the terminal as our focus. In this workshop we are going to use more of RStudio, and so will set up the workspace in a different way.
We are going to use the “Console” on the left-hand pane, the “Environment” in the top right, and the “Help” in the bottom left. Click on the tabs in these panes to make sure that these are visible, e.g. looking something like this:
In Beginning R you saw that R scripts are just text files that contain instructions written in the R programming language. You wrote text files, saved them, and then ran them via Rscript, which is the R interpreter program.
The RStudio Console provides an interactive way of running R commands. The Console is an interactive window in which R commands are run as you write them.
For example, click on the console window and type into it;
print("Hello R!")
When you press “return” you will see that you see that the R command is interpreted immediately, with the result printed directly below the command.
This is very useful, as it means that you can write and run R interactively.
You can also get help by putting a ? before a command. For example type
?print
and press return. You should see help for the print function displayed in the help pane on the bottom left.
You may also have noticed that, as you typed, a pop-up appeared that tried to suggest auto-completions for your typing. If you move your mouse over any of those auto-completions you will also see a short descriptive help text for the function:
Next, type into the console
my_list <- c(1, 2, 3)
and hit return. This will create a list. You will see this list appear in the Environment pane on the top right;