Rcpp.h,RcppArmadillo.hなど基礎
- "
"はここにあるように、RcppArmadilloでRの乱択ができるように書かれたhファイルだが、その中で#include しているので、RcppArmadillo.hのいろいろも使えている(ここも参考) - C:\Users\hogeUserName\Documents\R\win-library\3.0\RcppArmadillo\include\RcppArmadilloExtensions にインストールされていた。
- 似たようなところにある"RcppArmadillo.h"は以下のように"Rcpp.h"をincludeしていて、バッティングしないように警告がある
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- // // RcppArmadillo.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2012 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>. #ifndef RcppArmadillo__RcppArmadillo__h #define RcppArmadillo__RcppArmadillo__h #ifdef Rcpp_hpp #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'." #endif #include <RcppArmadilloForward.h> #include <Rcpp.h> #include <RcppArmadilloWrap.h> #include <RcppArmadilloSugar.h> #endif
- さらにそのRcpp.hは以下のようにいろいろ用意してくれているので、いろいろできる(数学計算なんかもできる)
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // Rcpp.h: R/C++ interface class library // // Copyright (C) 2008 - 2009 Dirk Eddelbuettel // Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // // Rcpp is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // Rcpp is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Rcpp. If not, see <http://www.gnu.org/licenses/>. #ifndef Rcpp_hpp #define Rcpp_hpp /* it is important that this comes first */ #include <RcppCommon.h> /* new api */ #include <Rcpp/exceptions.h> #include <Rcpp/RObject.h> #include <Rcpp/Promise.h> #include <Rcpp/S4.h> #include <Rcpp/Reference.h> #include <Rcpp/clone.h> #include <Rcpp/grow.h> #include <Rcpp/Dimension.h> #include <Rcpp/Environment.h> #include <Rcpp/Evaluator.h> #include <Rcpp/Vector.h> #include <Rcpp/sugar/nona/nona.h> #include <Rcpp/Fast.h> #include <Rcpp/Extractor.h> #include <Rcpp/XPtr.h> #include <Rcpp/Symbol.h> #include <Rcpp/Language.h> #include <Rcpp/DottedPair.h> #include <Rcpp/Pairlist.h> #include <Rcpp/Function.h> #include <Rcpp/WeakReference.h> #include <Rcpp/StringTransformer.h> #include <Rcpp/Formula.h> #include <Rcpp/DataFrame.h> #include <Rcpp/Date.h> #include <Rcpp/DateVector.h> #include <Rcpp/Datetime.h> #include <Rcpp/DatetimeVector.h> #include <Rcpp/Module.h> #include <Rcpp/InternalFunction.h> #include <Rmath.h> #include <Rcpp/sugar/undoRmath.h> #ifndef RCPP_NO_SUGAR #include <Rcpp/sugar/sugar.h> #include <Rcpp/stats/stats.h> #endif // wrappers for R API 'scalar' functions #include <Rcpp/Rmath.h> // this stays at the very end, because it needs to // 'see' all versions of wrap #include <Rcpp/internal/wrap_end.h> #include <Rcpp/api/meat/meat.h> #endif
#include <RcppArmadilloExtensions/sample.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp ; // [[Rcpp::export]] IntegerVector factorial_int(int n) { IntegerVector x(n); x[0] = 1; for(int i=1;i<n;++i){ x[i] = x[i-1]*(i+1); } return x; }