1 of 23

What’s R?

2 of 23

History

  • S language (Bell Labs)�
  • Ross Ihaka & Robert Gentleman

Ross Ihaka and Robert Gentleman. R: A language for data analysis and graphics. Journal of Computational and Graphical Statistics, 5(3):299–314, 1996

  • Open source since 1995

3 of 23

The philosophy of S (thus R)

“[W]e wanted users to be able to begin in an interactive environment, where they did not consciously think of themselves as programming. Then as their needs became clearer and their sophistication increased, they should be able to slide gradually into programming, when the language and system aspects would become more important.” - John Chambers

they needed to build language that would be suitable for interactive data analysis (more command-line based) as well as for writing longer programs (more traditional programming language-like).

4 of 23

Usage

R is heavily used by

  • pharmaceutical companies
  • academia
  • public health
  • hospitals
  • biostatistics
  • genomics
  • clinical trials

5 of 23

Current stats

  • TIOBE Index: R consistently ranks within the top 10 to 20 programming languages globally. (historic peak #8 in 2020)

https://www.tiobe.com/tiobe-index/

  • CRAN Repository: The Comprehensive R Archive Network (CRAN) hosts over 21,000 official packages. This repository continues to expand by 1,500 to 2,000 packages annually, nearly tripling its size since 2015.

  • Job Overlap: In data science job postings across platforms like LinkedIn and Indeed, 35% to 40% of positions explicitly request both R and Python.

6 of 23

INTRODUCTION TO R

FOR DATA SCIENCE AND BIOINFORMATICS

Siras Hakobyan, Davit Hakobyan

ABI

davit.hakobyan@abi.am, siras.hakobyan@abi.am

7 of 23

PLAN OF THE DAY

OMICSS-26

Time

Activity

18:00–18:10

Installation troubleshooting

18:10–18:20

Why R? History, ecosystem, where it is used

18:20–18:45

R syntax lecture

18:45–19:00

Quick syntax warm-up test (W3Schools)

19:00–19:10

Break

19:10–20:00

The R mindset: Vectorization and Data Manipulation Workshop

8 of 23

WHAT CAN BE FOUND ON GITHUB?

  1. This Lecture
  2. Exercises for R practice and the test
  3. Guide for Addressing R package installation problems
  4. Other useful resources

OMICSS-26

9 of 23

Outline

  1. Basic R Syntax
  2. Variable Types in R
  3. Vector and String operations
  4. Basic Functions in R
  5. Help & Source Code Access
  6. Control Structures
  7. Creating Your Own Functions
  8. Packages and Libraries
  9. Installing Bioinformatics Packages

OMICSS-26

10 of 23

Why Learn R?

    • Open-source and widely used in data science and bioinformatics
    • Powerful for data manipulation, visualization, and statistical analysis
    • Extensive ecosystem of packages (e.g., Bioconductor)

OMICSS-26

11 of 23

R Syntax Basics

How to assign variables

There are three ways to assign a variable in R:

    • Simple assignment,
    • Leftward assignment
    • Rightward assignment.

The most widely used is leftward assignment

OMICSS-26

12 of 23

Comments with #

R Syntax Basics

OMICSS-26

13 of 23

Case sensitivity

R Syntax Basics

OMICSS-26

14 of 23

Variable Types And Data Structures In R

OMICSS-26

15 of 23

Vectors in R: Basics and Operations

What is a Vector in R?

  • A vector is a basic data structure in R that contains elements of the same type.
  • You can create a vector using the c() function (combine).

Arithmetic Operations on Vectors

R performs element-wise operations when vectors are of the same length:

If lengths differ, R recycles the shorter one:

OMICSS-26

16 of 23

String Vectors and Concatenation

Vectors can store strings

We use paste() or paste0() to concatenate elements:

grepl(pattern, vector) checks for a pattern match, returns a logical vector

sub() – replaces the first match in each string

gsub() – replaces all matches

OMICSS-26

17 of 23

Basic Functions

dim()

OMICSS-26

18 of 23

Help & Source Code Access

View(mean)

OMICSS-26

19 of 23

If/else

Control Structures

for loop

while loop

break

next

OMICSS-26

20 of 23

Functions in R

Step 1: Define a function

Step 2: Call the function

Why use functions?

    • Reuse code
    • Keep things organized
    • Avoid repeating yourself (DRY principle)

mini-machines for repeated tasks

May have multiple arguments

May not return a value

May have a default value for an argument

OMICSS-26

21 of 23

Packages and libraries

    • Packages are collections of functions, data, and documentation developed for specific tasks: “toolkits” that extend R’s functionality.
    • Library refers to the location where packages are stored, and also the function used to load them (library()).

How to install and load packages

Popular packages and their functionalities

OMICSS-26

22 of 23

INSTALLING BIOINFORMATICS PACKAGES

R has a powerful ecosystem for bioinformatics, mostly through the Bioconductor project and GitHub-hosted tools.

Bioconductor packages are curated and widely used in genomics, transcriptomics, and more.

Useful when packages aren't on CRAN or Bioconductor yet (e.g., new analysis methods).

OMICSS-26

23 of 23

That’s it!

Thank you for your attention

OMICSS-26