R is a programming language that is very useful for
statistical analysis and data visualisation. The easiest way to use R is
to download an integrated development environment (or IDE), called
RStudio, which can be downloaded here: https://posit.co/products/open-source/rstudio/.
The main reason why RStudio is useful is because you can run code
line-by-line, which makes it easier to understand what each
line is doing. This helps pinpoint where any errors in the
code might originate from.
1. Using RStudio
RStudio has four panes that each display different information. The
image below shows how these four panes look while processing and
visualising some PL data:
The first pane is the code editor, where you can write and
save lines of R code.
To run some code, you can highlight which lines of code you want to run
and press the ‘Run’ button in the top right, or you can
press the button next to it and run everything!
The second pane shows information about your current
workspace.
In the example below, all the variables I have defined
after running my R script are displayed in the
‘Environment’ tab.
This includes dataframes, which contain rows and columns of
data, as well as different values, such as numbers, words, or
lists.
The third pane is the console.
If you run code from the code editor, it will show up in the console,
along with any outputs from each line of code.
You can also directly type lines of code into the editor - this is
useful when the code you are writing does not need to be part of your
main R script, for example if you just want to check or view something:
The final pane is where any outputs are displayed.
For example, if you have written some code to make a graph, the graph
will be displayed under the ‘Plots’ tab.
You can also view files in your current working directory under the
‘Files’ tab.