The aim of this tutorial is to introduce you to the basics of RStudio, which is a very useful graphic user interface (GUI). The default installation of RStudio might contain an old version of R. Please make sure that you also install a recent version of R (at least version: R-4.0.0).
We recommend to use RStudio to manage your R-code (in a file called ‘file.R’, where you can replace ‘file’ with any name you like) separate to your executed code in the Console window. It also holds plots, the environment and history window. In this ‘file.R’ you can store the useful and checked code for future use. For example, you could start a new R file and store in it all the commands below.
With the following screenshot of RStudio, we would like to focus on different useful parts.
The R-file (simid_R_tutorial.R
in this case) in
which you can add and modify code and save afterwards. You can execute
the code (see below).
Your working directory. This is the folder on your computer in which you are working. It is likely to be the folder in which the R code is saved (but it doesn’t have to be). Each computer will have a different specified address for the working directory. Upon opening RStudio, you can find out “where you are” using
The console where you can by type (or copy and paste) the R
commands to execute (hit enter
).
Window for plots. Use the arrows to get previous plots back.
Select R-code in your document and press the “Run” button to
execute. Or use the short cut cmd + enter
on MacOS or
shift + R
on Windows.
“Source” button to execute the active R-script.