Getting Started: A Quick Introduction to R

Welcome to the world of R! If you’re new here, don’t worry — you don’t need to be a coding wizard to get things done. R is a programming language designed with data in mind, and with the right tools, it becomes surprisingly intuitive.

In this short bonus lesson, we’ll walk you through the essential building blocks of R: how to store values in objects, use functions, and load packages. Just enough to help you feel at home before jumping into our data visualization course!

Free7 minutes read

👩‍💻 Executing R Code

You’ll usually use R inside an IDE (Integrated Development Environment), like RStudio, Positron or Visual Studio Code, which helps you write code, view data, and keep things organized.

While you'll likely use an IDE when working on your own projects, during the course you will write, modify, and run code in our sandboxes: A simple console where you can write R code and see the results immediately inside our browser 🧑‍💻

Try some basic operations below:

Loading...

→ Cmd + R

You can write any R code in the left panel (the console) and click  Run Code  to see the results in the right panel.

The  Reset  button will restore the initial example code.

Lines starting with # are comments. They're not executed — you can use them to temporarily disable code lines but also important to explain your code. Get into the habit of writing clear comments as they'll save time later when revisiting your own code!

Now that you’ve seen R in action, let’s take a step back.

🛠️ What is R?

R is a programming language built for data — from simple calculations to advanced statistical analyses and data visualizations. Today, it offers a versatile toolkit that goes far beyond the statistical roots it’s known for: you can write reports and books, build interactive dashboards and web apps, generate automated email updates, create data-driven art or interactive charts and maps, or even build custom APIs and websites.

Invented a long time ago — back then in 1993 📼 — R is becoming more and more popular and, thanks to its growing ecosystem and community, more approachable than ever.

👷 Building Blocks of R

Now that you’ve dipped your toes into writing R code, let’s look at the basic building blocks that make up most R scripts. You don’t need to memorize everything — just get familiar with the concepts and how they work together.

🛒 Objects

In R, you often store values — like numbers, text, or entire datasets — in objects. These are named containers that hold information, so you can reuse it or refer back to it later by the object name.

Loading...

→ Cmd + R

🗃️ Data Types

When you create an object in R, it doesn’t just store a value — it also remembers what kind of value it is. These are called data types, and they matter because they tell R how to treat the data.

The most common types are:

R usually figures out the type for you, but you can always check with class().

Loading...

→ Cmd + R

👯 Vectors

Very often we will store multiple values in a single object. R is particularly good at working with vectors, a sequence of items with a particular data type. You can create one by wrapping its contents in c() (short for "concatenate") and apply the same logic to each item:

Loading...

→ Cmd + R

📋 Data Frames

By now, you've worked with single values and vectors. But real-world data usually comes in tabular form — what's usually called a table or spreadsheet, we call a data frame in R.

A data frame is basically a bunch of vectors stuck together, column by column. You can create your own data frames with the data.frame() function:

Loading...

→ Cmd + R

R also has matrices (like a data frame, but only one type of data allowed) and lists (more flexible, but a bit messier). They’re useful too — but we'll be working with data frames only.

🧰 Functions

Functions do things. They’re like little machines: you give them input, and they return output.

In most cases, functions are used with parentheses () — just like c() above! And in the best case, they have a meaningful and easy-to-grasp name:

Loading...

→ Cmd + R

Many functions take multiple arguments. You can pass them in order (called positional or implicit matching) or by naming each one, which allows you to flip them around (called named or explicit matching):

Loading...

→ Cmd + R

Creating your own functions is actually not that hard as well! To do so, you have to fill the following template:
name <- function(arguments) { code }.

When you call the function with specific inputs, it runs that code and returns a result:

Loading...

→ Cmd + R

Don’t worry if it still feels a bit abstract — writing your own functions is a more advanced skill, and we’ll guide you through it step by step later in the course!

For now, it’s good to know what a function looks like under the hood. Most of the time, you’ll be using functions that come from R packages — and that’s exactly what we’re about to explore next!

📦 Packages

R gets its power from packages: collections of functions, data, and documentation. You can install a package once via install.packages("packageName") and then load it whenever you need it with library(packageName).

Our course makes heavy use of ggplot2 package — to use its functionality we have to install and load it first:

🏆 Exercises

You’ve learned the basics of programing in R — now let’s turn knowledge into skill!

Time to practice what you’ve learned 💪

🚀 What next?

That’s it for our quick tour of R fundamentals! If you're ready to move on, you can dive into the main course to learn:

 → why we think coding charts is a great idea
 → how to create charts with ggplot2 right away

Wherever you head next, we hope this foundation will help you write and understand R code with more confidence!

Next →

Your Own Project