들어가며

R은 통계를 전공하는 사람들이 가장 많이 사용하는 계산 언어 중 하나이다. R을 사용함에 있어 가장 답답한 부분 중 하나는 반복문(for문, while문)이 매우 매우 느리다는 것이다. 이러한 문제를 해결하는 방법 중 하나는 컴파일 언어인 C/C++ 또는 Fortran을 이용하는 것이지만, 이를 단기간에 배우는 것은 쉽지 않다.

R에는 컴파일 언어인 C/C++을 사용하기 편리하도록 만들어진 Rcpp이라는 패키지가 있다. (Eddelbuettel, Francois, Allaire, et al. (2024)) 또한 C++에서 선형대수 라이브러리인 Eigen, Armadillo 또한 사용할 수 있도록 각각 RcppEigen (Bates et al. (2024)), RcppArmadillo (Eddelbuettel, Francois, Bates, et al. (2024))를 제공하고 있다.

여기서는 R 사용자를 위한 기본적인 Rcpp 사용법과 선형대수 연산을 위한 RcppEigen, RcppArmadillo의 사용법에 대해 정리한다. 필자 또한 C++을 전문적으로 배운 경험은 없으며, R 프로그래밍을 하며 연산속도 향상을 위해 부분적으로 C++을 사용하는 방법 위주로 정리해보려 한다.

References

Bates, Douglas, Dirk Eddelbuettel, Romain Francois, and Yixuan Qiu; the authors of Eigen for the included version of Eigen. 2024. RcppEigen: Rcpp Integration for the Eigen Templated Linear Algebra Library. https://github.com/RcppCore/RcppEigen.
Eddelbuettel, Dirk, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russell, Inaki Ucar, Douglas Bates, and John Chambers. 2024. Rcpp: Seamless r and c++ Integration. https://www.rcpp.org.
Eddelbuettel, Dirk, Romain Francois, Doug Bates, Binxiang Ni, and Conrad Sanderson. 2024. RcppArmadillo: Rcpp Integration for the Armadillo Templated Linear Algebra Library. https://github.com/RcppCore/RcppArmadillo.