simcdm
in R
packagesThe design of simcdm
allows the package to be included
in other R packages using either the R or C++
functions. The next section details provides with how to incorporate
either the R or C++ functions into a new R
package or standalone C++ file.
Note, if you are not familiar with compiled code in R please feel free to use the traditional way to import the R functions.
To use simcdm
’s R functions
only in your own R package, modify the
package’s DESCRIPTION
file by adding an imports
declaration.
Inside of the package’s NAMESPACE
file, make sure to
use:
If you are using roxygen2
to manage the packages
NAMESPACE
file, add the following tag and re-run the
roxygenize()
function.
Within a C++ file in src/
, then add:
#include <RcppArmadillo.h>
#include <simcdm.h>
// [[Rcpp::depends(simcdm, RcppArmadillo)]]
// [[Rcpp::export]]
arma::mat example_dina_sim(const arma::mat &alphas, const arma::mat &Q,
const arma::vec &ss, const arma::vec &gs) {
arma::mat dina_items = simcdm::sim_dina_items(alphas, Q, ss, gs);
return dina_items;
}
To use C++ functions available in simcdm
within
your R package, modify your package’s DESCRIPTION
file by
adding:
LinkingTo: Rcpp, RcppArmadillo (>= 0.9.200), simcdm
Imports:
Rcpp (>= 1.0.0)
Reference the simulation functions using simcdm
namespace like so: