Rstudio is a complete environment for working with the R language. Once you have got used to it you will find that it makes working with R far more productive than using the R console version. However the concepts involved in using RStudio will be completely new to most. The interface can seem very complex. RStudio provides an interface for working with R code, rather than an interface for running analyses directly. The code for conducting analyses will be provided for you in this course. You do not need to learn to write any Rcode yourself in order to produce graphics and run basic statistical analyses. You will also be able to reproduce more sophisticated quantitative and spatial analysis in RStudio by making minor adaptations to pre-built scripts.
The RStudio server version runs directly through any web browser. There is no need to install any software on your laptop, PC or tablet
Access to the server is through the following URL. This works both on and off campus.
http://r.bournemouth.ac.uk:8789/
The usernames for this course have been set up to be your first name as shown in brightspace and surname initial, all in lower case.
veronicab elizabethe garethh minniej curtisl esmel ricardol robm ttomasn georgiap andrewr molliet anuro msc1 msc2 guest phd1
If your name is not in this list, or you want to change your user name let me know. Do not log in using someone else’s name!. If there is any abuse of this I will show users how to change to a secure password, but we will assume trust by default.
Using a server can seem strange at first. The RStudio server is an integrated platform for doing the following …
Amongst many other potential uses. It is a very powerful tool that is freely available for all those with a log in to use it. The more advanced features can be used without any programming skills through sharing scripts. However you do need to become familiar with some new concepts in order to use these.
The RStudio server is ideal for collaborative work. You have been provided with a username and a password, as this also provides you with your own permanent space on the server for saving your own work and building up a portfolio of useful analyses. Only one person can be logged in at any one time under your username. However I can always log into your user space at any time in order to help correct your errors and to give you advice.
Once you are logged in you will see three sections of the interface by default. This will change to four sections when you begin using scripts in the interface.
Look carefully at the interface and learn to recognise the sections.
A key concept to understand when using the server is that your home directory on the server is like a directory (folder) on your PC. So ,it is rather like the university H drive. However it is all “encapsulated” on the server which is also running R. So it is distinct from your H drive and not directly linked. In order to move data files and scripts into your home directory you must upload them. You will see buttons labelled New Folder, Upload, Delete, Rename and More. If you click on the More button you will also find an option to Export your files. The upload and the export buttons are frequently used to move files onto the server and to directly move files off the server. It is very important to be aware of this concept. Files saved on the server will always be available for use later. In contrast active analyses that take place in the server memory, as opposed to the server’s hard disk space, will be temporary and will be lost between sessions.
Just as we have seen previously in QGIS the use of projects is good practice. QGIS can be used without a project file, but if you do that you may find that you have to go through many steps to reload files and get back to where you left off. RStudio has a similar concept. We can use a project for each week’s work in R. Let’s start one called “intro”. Just as in QGIS each project should be associated with a single folder and all the work placed within this folder. The folder can be added when the project is first started.
The R console in the bottom left of the screen allows you to run R code interactively. In this course you will not be using this very much, as we will use pre-built R code that avoids the need to code your own. However in order to use the code you do need to gain some intuitive idea of what is happening when you do.
The action you have taken so far involves a concept that will be completely new to most of you. We can refer to it as data abstraction. Most of you will be familiar with data in the form of visible numbers, text, or even maps. However programmers (and mathematicians) think of data in the abstract. We have a data object (in this case a numerical vector) called x. It consists of 100 numbers. These numbers have been simulated by R from a normal distribution. However data analysts tend not to look directly at the numbers themselves. They are much more interested in patterns in the numbers and relationships between variables.
So what has happened here?
These concepts will become clearer over time when using R. Notice that at this stage no data is actually saved as a file on the hard disk. It is present in the computer’s memory.
This was a tiny R project, but we all have to start somewhere. Programmers often begin learning how to make the language they are learning send a “Hello World” message to the console. So this was the equivalent of “Hello R World”
Let’s go back to the project.
So, what’s going on?. When you answered “yes” to save the workspace both the data and the history of the R commands were saved in the folder. So the whole “analysis” can be recreated at any time. This will all become clearer over time.
This course will concentrate on the use of markdown documents as a way of running R code. The advantages of using markdown are many.
The steps above produce a default “demo” markdown document. Every time you start a new markdown Rstudio will start off with this one. When you use markdown for real you will either open a document ready for knitting or replace the default demo text with your own.
You should look at the logic of the document carefully. It consists of “chunks” of R code that produce output in the form of tables and figures embedded in text. The R code automatically produces output and adds it to the document after knitting. So if you have R code available that will run an analysis that you are interested in you don’t have to remember any other steps in order to run it. Simply ensure that the data that is being added to the analysis is appropriate for the type of analysis being run and you can obtain the same results with your own data. This will be the way R is used in this course.
You should now be able to start a clean project in RStudio. The code to actually run the analyses will be provided for you. So there is no need to fully understand R code to complete the unit. You will not be expected to write any code yourself. However, as you progress with R you will begin to alter code and adapt it for your own purposes. With time you will be able to write code yourself to run analyses. The key to the process is to become familiar with the general concept of data abstraction and to gain a feel for the nature of the data that is used for statistical analysis.