R Tutorial: Optimizing R Code with Rcpp | Intro
Key Takeaways
This video tutorial introduces the Rcpp package, which allows users to optimize their R code by writing critical paths in C++. The course covers basic C++ syntax, C++ functions, and how to manipulate R vectors in C++.
Full Transcript
welcome to this course my name is Roman Francois I'm one of the authors of the LGBT package and I will be your instructor our is a great language but sometimes it's slow that is because our is an interpreted language our expressions are passed and interpreted at runtime on the other end C++ is a compiled language the C++ compilers do a great job of translating C++ statements into machine code that runs much faster in this course you will learn how to use the RCP package to make your code faster by writing critical paths in C++ you don't need to know everything there is to know about C++ but only a small subset it has always been possible to use C or C++ in your our code but our CPP makes the process very easy you only have to focus on writing simple C++ code and our CPP takes care of converting our objects to C++ and vice versa the course is divided into four chapters that will gradually equip you with skills to take advantage of C++ in your R code the first chapter covers basic C++ syntax the second chapter is about C++ functions you will learn how to write them and how to make them available to our most of the time using our CBP consists of manipulating our vectors you will learn in the third chapter how to access existing our vectors and create new ones finally in the last chapter you'll practice your new skills on many case studies when you use our CPP you typically want to keep the main logic of your code in R and resort to C++ for data intensive work or when your our code cannot easily be expressed with vectorized functions the micro benchmark package will help you to compare performance of two or more versions of your code for example the initial our code and the supposedly optimized C++ version as illustrated here micro benchmark takes any number of our expressions evaluates them hundred times each and then summarizes the information we typically only look at the median : for more information about benchmarking and profiling that is finding the actual bottlenecks in your code please refer to the datacom course writing efficient R code by : Gillespie as a compiled language C++ does not offer a console for interactive use but our CPP is a few utilities to mimic that the eval CPP function takes a string of valid C++ code compiled it under the hood and evaluates it this is often used to check if a machine has been properly set up to use our CPP C++ has a rich set of basic number types you will only use integers of type int and floating-point numbers of type double because those are the types used in our there's a difference between our C++ about literal numbers in our literal integer numbers are doubles by default and you have to convert them explicitly to introduce using either as dot integer or with the capital L suffix in C++ literal integer numbers are integer and you can suffix them with dot 0 to force them to be a double to convert explicitly to a double you can also use casting with the syntax presented here the name of the target type your double between parenthesis before the object being cast casting to a double is sometimes necessary for example C++ uses integer division when both operands are int whereas our promotes automatically to doubles when needed now it's your turn to write some basic C++ code
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/optimizing-r-code-with-rcpp at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Welcome to this course, my name is Romain François, I am one of the authors of the Rcpp package and I will be your instructor.
R is a great language, but sometimes it is slow.
That is because R is an interpreted language. R expressions are parsed and interpreted at runtime. On the other hand, C++ is a compiled language. The C++ compilers do a great job of translating C++ statements into machine code that runs much faster.
In this course, you will learn how to use the Rcpp package to make your code faster, by writing critical parts in C++. You don't need to know everything there is to know about C++, but only a small subset.
It has always been possible to use C or C++ in your R code, but Rcpp makes the process very easy. You only have to focus on writing simple C++ code, and Rcpp takes care of converting R objects to C++ and vice versa.
The course is divided into 4 chapters that will gradually equip you with skills to take advantage of C++ in your R code.
The first chapter covers basic C++ syntax.
The second chapter is about C++ functions. You will learn how to write them, and how to make them available to R.
Most of the time, using Rcpp consists of manipulating R vectors, you will learn in the third chapter on how to access existing R vectors and create new ones.
Finally, in the last chapter, you'll practice your new skills in mini case studies.
When you use Rcpp, you typically want to keep the main logic of your code in R, and resort to C++ for data-intensive work or when your R code cannot be easily expressed with vectorized functions.
The microbenchmark package will help you to compare the performance of two or more versions of your code. For example, the initial R code and the supposedly optimized C++ version.
As illustrated here,
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
🎓
Tutor Explanation
DeepCamp AI