Session Ready
Exercise

Simple C++ Expressions with evalCpp

Unlike R, you don't have access to a console in C++ to experiment iterations of your code.

To ease into C++ gradually, Rcpp provides the evalCpp() function that takes a simple C++ expression as a string, compiles it into a proper C++ function, and calls that function.

This is often used to check if a machine is properly configured to work with Rcpp.

Instructions
100 XP
  • Load the Rcpp package.
  • Evaluate 2 + 2 as a C++ expression with evalCpp() and also as an R expression.
  • What are the storage modes of x and y ?
  • Change the C++ expression 2 + 2 so that it returns a double and assign it to z.