R Tutorial: What is Object-Oriented Programming?
Key Takeaways
This video tutorial by DataCamp introduces the concept of Object-Oriented Programming (OOP) in R, covering the basics of OOP and its application in R using S3 and R6 classes.
Full Transcript
hi I'm Ritchie I'm a data scientist at data camp and I'll be your instructor for this course most of the time when you work with our you use a functional programming style that is you start with some data to manipulate it you apply a function this returns some new data then you apply another function and you repeat this and till you get an answer with a functional mindset you typically start by thinking about what you want to function to do next you worry about the objects that get passed into the function that is the arguments to that function and finally you worry about the objects that come out the other end that is the return values object-oriented programming has a different approach in it you start by thinking about the objects that you have to work with in this case a teapot and then you think about what data you need to describe the object for a teapot you might want to store the total capacity and how much liquid is currently stored in the pot next you think about the functionality of that object the main purpose of the teapot is to pour tea so you had a pour function in object-oriented programming functions and owners methods there is no special method type of variable in R so throughout the course whenever you hear the word method it just means a function but used in an object-oriented context you've already come across many of the object types that are available in R for example you seen numeric logical and character vectors as well as factors data frames and lists in total there are about 20 types of objects available in our the exact number depends on how you count them these are all the basic building blocks that you need for data analysis there are two variable types here that become important for object-oriented programming lists and environments because these variable types can contain other variables you can use them to create many other more complex types think of it like Legos and this case you have twenty types of Lego block but you can use those blocks to build an infinite number of more complex structures before we begin a word of warning a lot of the time object-oriented programming isn't necessary or even desirable for data analysis most of the time you want your data to be stored in a data frame and you should use functions that take a date frame manipulate it and return another data frame that is the functional programming approach this is the philosophy of the tidy verse packages most notably deep liar after you've finished this course take one of our deep liar courses to see the alternate approach so what should you use object-oriented programming it works best when you have a limited number of objects that you completely understand the behavior of this is true of industry specific data analysis for example the bioconductor project has over a thousand are packages for analyzing biological data particularly genomics sections of a genome occur in many contexts here so many bioconductor packages make use of a genomic range object by reusing this object throughout bioconductor the behavior is predictable across many packages another example is accessing data through web application programming interfaces or api's in this case there is a limited number of responses that the website can provide and you can define objects to store these responses a third example is graphical user interfaces or gooeys many of the languages used to build gooeys such as java or c sharp are object oriented for a GUI again there are a small number of well understood objects that you need to consider like buttons or text boxes or checkboxes this screenshot is from a shiny app which means that it's a web GUI built in our what you may notice about all three examples is that none of them really involved any data analysis just to make it really clear object-oriented programming is brilliant for building tools for data analysis but bad for data analysis itself in fact there is no data analysis in this course at all instead the focus is on learning important coding skills to summarize with functional programming you think about the functions first and then how you use them on your data with object-oriented programming by contrast you think about the data structures first and then worry about their functionality for general-purpose data analyses the functional style is more appropriate an object-oriented style is preferable when you have a limited number of complex objects now let's try some examples
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/object-oriented-programming-with-s3-and-r6-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Hi, I'm Richie. I'm a data scientist at DataCamp and I'll be your instructor for this course. Most of the time when you work with R, you use a functional programming style.
That is, you start with some data. To manipulate it, you apply a function. This returns some new data. Then you apply another function, and you repeat this until you get an answer.
With a functional mindset, you typically start by thinking about what you want a function to do. Next you worry about the objects that get passed into the function - that is, the arguments to that function.
Finally you worry about the objects that come out the other end - that is, the return values. Object-oriented programming has a different approach.
In it, you start by thinking about the objects that you have to work with - in this case a teapot. Then you think about what data you need to describe the object. For a teapot, you might want to store the total capacity, and how much liquid is currently in the pot. Next you think about the functionality of that object.
The main purpose of a teapot is to pour tea, so you'd add a pour function.
In object-oriented programming, functions are known as methods. There is no special "method" type of variable in R, so throughout the course, whenever you hear the word "method" it just means a function, but used in an object-oriented context.
You’ve already come across many of the object types that are available in R. For example, you’ve seen numeric, logical and character vectors, as well as factors, data-dot-frames, and lists.
In total, there are about twenty types of objects available in R - the exact number depends on how you count them. These are all the basic building blocks that you need for data analysis. There are two variabl
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
Related AI Lessons
⚡
⚡
⚡
⚡
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Medium · ChatGPT
How to prepare for Spain civil service TIC exam using AI in 2026
Dev.to · David García
Going Viral! How I Created AI Kissing Videos Step by Step Easily Using AIAI.com
Medium · AI
How to prepare TIC teacher exams in Spain with AI (oposiciones 2026)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI