เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Boiler plate

As you saw in the previous exercise, the code below does not compile.

#include <Rcpp.h>
using namespace Rcpp ; 

double twice(double x){
    return x + x
}

Let's modify it.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Optimizing R Code with Rcpp

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Fix the syntax error on the function's return line (line 8).
  • Add an [[Rcpp::export]] decorator so that the function is exported to R.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

#include 
using namespace Rcpp ; 

// Export the function to R

double twice(double x) {
    // Fix the syntax error
    return x + x
}
แก้ไขและรันโค้ด