Get startedGet started for free

Congratulations!

1. Congratulations!

Congratulations, you've completed this course. You should now feel comfortable tackling some real life problems by combining the nice R syntax you all know and love with some simple C++ functions in the background to leverage performance. Writing more performant R code usually means learning more vocabulary. As much as this is always a good idea, you have now gained the capability to write your own vectorized functions, as in fact vectorized functions are nothing more than a loop written in a compiled language like C++. Let's go through the topics we discussed together one more time.

2. evalCpp and cppFunction

Early in the course, you'vd learned "evalCpp" and "cppFunction", two R functions from Rcpp that got you started with C++.

3. For loops

In chapter two, you also learned how to write C++ loops. If you only have space to remember one of these, go with the for-loop, that's the most important one. The syntax of the for loop is different than the syntax you'd use in R. They are more flexible, but they require slightly more work. They are made of 4 components. - The initialization, where you create variables used in the loop. - The continue condition, executed before each iteration, which controls whether the loop should stop or continue. - The increment, executed at the end of each iteration. - The body of the loop, which is the code that is executed at each iteration.

4. For loops

Within this general for loop model, one particularly idiomatic version is used much more often. You will use this version to iterate through elements of vectors.

5. Vector indexing

Remember that in C++ indexing starts at 0. Keep in mind that the loop index represents an offset, the number of positions after the start of the vector. Then the value at index 0 is the first value of the vector, the value at index 1 is the second value, and so on ... if n is the length of the vector, the value at index n-1 is the last value.

6. C++ files with Rcpp

In chapter 3 and 4, you worked on C++ files to be loaded with the "sourceCpp" function. Let's review what these files contain again. First you include the Rcpp codebase with Rcpp header file, then you declare using Rcpp namespace. That means that you will not have to type Rcpp colon colon every time you use a class or a function from Rcpp. Cpp files usually contain one or more exported functions. An exported function is preceded by the "Rcpp::export" comment to indicate to Rcpp that these are special.

7. Typical Rcpp function

Towards the end of the course, you also created several functions, all using for loops around one or more vectors. You might get the impression that writing for loops is all you do in C++, and that is mostly the case.

8. Congratulations!

I hope that you have enjoyed the course, and I'm sure we'll meet again, maybe here for another course, in real life or perhaps on twitter. In the meantime, up to you to make great and fast things with Rcpp.