Workspace setup

There are lots of different ways to run R code and many tools to help you write it. You don’t require any special tools to create an R script, a simple text editor like Notepad on Windows is sufficient. More advanced tools include IDEs like RStudio or Visual Studio Code.

For this workshop we will be keeping things as simple as possible in order to allow us to focus on the topics we’re learning without having to learn too many extra tools along the way.

For the purpose of this course we will be using a free tool called RStudio which provides you with an integrated enviroment where you can write and run R code. The easiest way to get access to R and RStudio is first downloading and installing the latest R version from https://cran.rstudio.com/, and after downloading and installing RStudio from https://posit.co/download/rstudio-desktop/. You may need administrator access to install R and RStudio on your computer. Both tools are freely available for Windows, MacOS and Linux.

Installation on University managed computers

If you are using a University of Bristol computer, you will find R and RStudio in Company Portal.

Once both are installed, you can open RStudio and will look something like this:

The way that we will be setting up the space is to have a text editor on the top-left side of the screen and the R console on the bottom-left side. We’ll use the editor to write our code and the console to run it. On the right side we can keep other tabs open.

Working directory

Setting up a working directory helps organize your project files and ensures that your code can find any necessary resources and dependencies. We will revisit this concept later on, but for now be mindful that the space where you save your scripts has to be the same than the working directory where R console and/or your Command Prompt/Terminal are working,

In R Console you can print the current working directory it with

getwd()
[1] "/Users/ab12345"

Alternatively, if you are using the Command Prompt (Windows) you can check your current directory with

Command Prompt
cd

Or if you are using a Terminal (MacOS and Linux) you can check your current directory with

Terminal
pwd

We’re now ready to get started!