1. 学ぶ
  2. /
  3. コース
  4. /
  5. Optimizing R Code with Rcpp

Connected

演習

First function - again

Recall the the_answer() function from Chapter 1, that always returns 42. Let's rewrite it, this time in a C++ file.

The file's components are:

  1. An "#include" directive to get access to Rcpp functionality.
  2. A using namespace declaration, for convenient typing.
  3. The function definition.
  4. An Rcpp R comment block, to call the function once the C++ code is compiled.

指示

100 XP
  • Include the Rcpp.h header file.
  • Declare that you use the Rcpp namespace.
  • Make the function return 42.
  • In the Rcpp R comment block, call the function.