Start out by installing R and then RStudio1
Learn things that last longer - pick your battles - Learn the fundamentals2
R is a powerful programming language for data analysis, statistics, visualisation and more. RStudio is the program that interacts between you and the language R. R and RStudio are two free available software with a huge community of users and developers.3
At the end of this session you will be able to:
Please create a folder called “RProjects” under “Documents” This is important for our project data management.
There are four main panels on RStudio.
Create three folders in your project5. Remember to use naming conventions or check6.
There are three ways to find help using RStudio8
sessionInfo
list.files
ls
Comments start with #.
# Description:
# Author:
# Date:
To add a section
# Starting with objects --------------------------
To get the hang of R, we start using it as a simple calculator. Type 2 + 2 directly into the console panel and press enter. You should see this:
2 + 2
## [1] 4
R can calculate and store multiple values in variables or objects so we can access them later. Use: objectname <- value
.
<-
I recommend two style guides:
many_numbers <- c(1, 2, 5.3, 6, -2, 4) # numeric vector
many_numbers
## [1] 1.0 2.0 5.3 6.0 -2.0 4.0
You can create either a vector of characters or a vector of logicals
""
for each valueTRUE
and FALSE
## [1] "one" "two" "three"
## [1] TRUE TRUE FALSE
Let’s introduce some data to R
download.file(url = "http://tiny.cc/csvexample",
destfile = "data/example.csv")
mydata <- read.csv(file = "data/example.csv")
read.csv
9str
with your new objectTip10
Most R package you can be installed it like this: install.packages("packagename")
Then you need to load it using library(packagename)
Then go to the fourth panel and select the packages tab, after loading a package it should be checked.
You can also check sessionInfo()
“File” “close project” (It asks if you want to save your data), then you can close RStudio.
There are plenty of R resources, this is only a short list.
Please send your annonymous feedback through this link http://tiny.cc/elixir_feedback
This handout was written in Rmarkdown, and uses the open-source Tufte style. It has been published on Github pages and also as a PDF handout.
All of the information of my courses can be found on my Github repo R for Data Analysis. These resources are freely available under the Creative Commons - Attribution Licence. You may re-use and adapt the material in any way you wish, without asking permission, provided you cite the original source. That is a link back to the website R for Data Analysis and my ORCID 0000-0002-8990-1985.
I acknowledge this publication is resulting from support of Elixir-Belgium for my role as data science and bioinformatics trainer.
Last update: 2018-02-09
See installation instructions installation.md↩
“Learning to code is a never ending journey with a set of challenges and delights unique to each person”↩
FYI: Projects make managing multiple directories straightforward↩
In RStudio, you can use the fourth panel then click “Files” then “New Folder”. Or you can use the function dir.create
↩
You can run code from a script using “Ctrl+Enter” (line by line or a selection of code)↩
The help panel will show you the Documentation. How to use a function, input, details, and examples↩
You can also read other kinds of file using read.table
or special packages↩
Always use the help in RStudio if you don’t know how a function works↩