Basic intro in RStudio

20 Jan
2022

RStudio is a great interface to work with the programming language R. You can learn the basics of using RStudio in just a few minutes in this tool!

What is R and RStudio?

R is a powerful programming language that is most commonly used in science for things like statistical analysis and data presentation. R is the software that actually performs the given instructions, and RStudio is a programme that provides a nice interface for working with R. You can use R without RStudio, but not vice versa! As both are free downloadable software, I recommend you download both to get the most out of using RStudio, which is explained in this tool.

The basic interface of RStudio

When you first open RStudio, there are four main panels (provided you open a new R script by clicking the 'add page' icon at the top left. What can we do in each of these four panels?

Top Left: Here is where you can write your actual code. You can press 'Run' to run the code. Try typing something yourself, such as a simple mathematical equation:

6 + 7
4 - 3
2 * 5

Once you click 'Run' you should see the answers to these equations appear in the bottom left panel.

Bottom Left (console): This is where your code prints to the screen after you run it. The answers to the mathematical equations should appear here (unless you save things as variables).

Note that you can also write code in this console, but it will not be stored for running again easily. Therefore, it is always recommended you write your code in the top left panel.

Top Right: Here is your global environment (everything you want to save; like the 'memory' of R) and you can look back at the history of what you have run.

How can we save things to the global environment? For this, we need the name of a variable (such as x), and an assigning symbol (<- or =). Try it out yourself:

x <- 6 + 7
y <- 4 - 3
x + y

Notice how the variables 'x' and 'y' have been saved as values in the global environment. Once saved here, R can remember the values of the variables, so that we can use them again. If we now run 'x + y', the answer is printed to the console (bottom left).

Assigning values to variables is a very useful function in R. It means you can refer to parts of the code again without having to write them out again e.g. we can write 'x + y' instead of '(6 + 7) + (4 - 3)'.

Bottom Right: This is a panel with several useful functions:

  • Files: here you can import files to use within R. E.g. you could import an Excel file with data so that you can do statistical tests on it, or make a graph with the data.
  • Plots: if you do make a graph, it will show up here once you run the code for the graph.
  • Packages: here you can download and install packages, which are like libraries containing code that R can understand (see explanation below).
  • Help: you can use this to search for functions within R to gain help about how to use them. E.g. try using the code 'help(sum)' - in the help box it should now tell you how to use the sum function.

Why do I need to install packages in R?

R has almost unlimited possibilities, so if we had all of them accessible and pre-installed at once this would take up far too much space on computers! This also increases the time needed for R code to run. Therefore, instead you can install packages as and when you need them - it's like getting a book out of a bookshelf when you need to read it, but putting the book back again once it is not needed anymore. The packages contain useful functions that R can understand and you can use to do more advanced things with your code. Note that several useful packages come pre-installed (such as basic mathematical ones).

How to start with R and RStudio

Coding in R can seem quite scary at first, but it is best to just try it out. Confidence and skills in coding is best built with experience, so play around with it! Also, check out the other R tools to learn more about specific functions and packages you can use.

Quantum Computing 101
Computer Science

Quantum Computing 101

Shifa Hussain Explains Quantum Computing

by:
Shifa Hussain
Sep 10, 2021
add
Add to saved tools
check
Saved
more_horiz
Please wait
LaTex scientific typesetting 1
Communication

LaTex scientific typesetting 1

LaTex is a typesetting system that is the gold-standard in academia. It allows for easy handling and editing of long documents. This short tutorial shows the basics.

by:
Fionn Ferreira
Feb 12, 2022
add
Add to saved tools
check
Saved
more_horiz
Please wait
Quadrat survey of a rocky coastline
Life Science

Quadrat survey of a rocky coastline

Using a quadrat-based survey method to perform an ecologial survey of a roacky coastline.

by:
Darcie Anderson
Feb 12, 2022
add
Add to saved tools
check
Saved
more_horiz
Please wait
Build a DIY incubator
Life Science

Build a DIY incubator

Build your own DIY Incubator for biotechnology experiments with materials you probably already have at home.

by:
Amino Labs
Jan 24, 2022
add
Add to saved tools
check
Saved
more_horiz
Please wait
Counting objects and measuring area in images
Life Science

Counting objects and measuring area in images

Using a common photo-editing software to count particles and measure areas on microscope images.

by:
Fionn Ferreira
May 11, 2021
add
Add to saved tools
check
Saved
more_horiz
Please wait
Build a basic IOS app using Swift
Computer Science

Build a basic IOS app using Swift

An introduction to using X-Code to build an IOS app. This tutorial focuses on getting to know the X-code and swift interface.

by:
Oisín O'Sullivan
May 10, 2021
add
Add to saved tools
check
Saved
more_horiz
Please wait
DNA Extraction
Life Science

DNA Extraction

DNA (deoxyribonucleic acid) is a protein found in all living cells that acts as a set of biological instruction. In this tool, we see how DNA can easily be extracted from fruit. Although DNA is a very small molecule, when collected from thousands of cells it is visible to the naked eye!

by:
Amino Labs
Jan 20, 2022
add
Add to saved tools
check
Saved
more_horiz
Please wait