カジュアルにC++11 in R
以下のプラグイン
plugins=c("cpp11")
をcppFunctionに指定するだけ。Winでもいけた。C++11なんで戻り値をdecltypeにしてやろうと思ったら、できなかった。windowsのgccが古いせいかな?
library(Rcpp) cppFunction(' std::vector<double> twoTimes(std::vector<double> xs) { for(auto &x : xs) { x *= 2.0; } return xs; }', plugins=c("cpp11"))
こんなかんじで。
> twoTimes(1:10) [1] 2 4 6 8 10 12 14 16 18 20
こうなる。