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:
- An "#include" directive to get access to
Rcppfunctionality. - A
using namespacedeclaration, for convenient typing. - The function definition.
- An Rcpp R comment block, to call the function once the C++ code is compiled.
Diese Übung ist Teil des Kurses
Optimizing R Code with Rcpp
Anleitung zur Übung
- Include the
Rcpp.hheader file. - Declare that you use the Rcpp namespace.
- Make the function return
42. - In the Rcpp R comment block, call the function.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
// Include the Rcpp.h header
#include <___>
// Use the Rcpp namespace
using ___ ___;
// [[Rcpp::export]]
int the_answer() {
// Return 42
return ___;
}
/*** R
# Call the_answer() to check you get the right result
___
*/