diff --git a/.gitignore b/.gitignore index 6b00f852..ea853699 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ src/*.gcda doc Meta *_cache* +*~ diff --git a/R/utils.R b/R/utils.R index 21a16a08..f6482d0b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -377,3 +377,33 @@ get_n_samples.array <- function(x){ stopifnot(is_3d_array(x)) return(dim(x)[1]) } + +#' Code to use the hesim package inline. Not directly called by the user. +#' @param ... arguments +#' @examples +#' library(Rcpp) +#' sourceCpp(code=" +#' // [[Rcpp::depends(hesim)]] +#' // [[Rcpp::depends(RcppArmadillo)]] +#' #include +#' // [[Rcpp::export]] +#' double test_inline_gengamma(double mu, double sigma, double Q) { +#' hesim::stats::gengamma gg(mu, sigma, Q); +#' return gg.random(); +#' }") +#' set.seed(12345) +#' test_inline_gengamma(1.0, 1.0, 1.0) +#' @keywords internal +#' @rdname plugin +inlineCxxPlugin <- function(...) { + ismacos <- Sys.info()[["sysname"]] == "Darwin" + openmpflag <- if (ismacos) "" else "$(SHLIB_OPENMP_CFLAGS)" + plugin <- Rcpp::Rcpp.plugin.maker(include.before = "#include ", + libs = paste(openmpflag, + "$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)"), + package = "hesim") + settings <- plugin() + settings$env$PKG_CPPFLAGS <- paste("-I../inst/include", openmpflag) + ## if (!ismacos) settings$env$USE_CXX11 <- "yes" + settings +} diff --git a/man/plugin.Rd b/man/plugin.Rd new file mode 100644 index 00000000..372a1892 --- /dev/null +++ b/man/plugin.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{inlineCxxPlugin} +\alias{inlineCxxPlugin} +\title{Code to use the hesim package inline. Not directly called by the user.} +\usage{ +inlineCxxPlugin(...) +} +\arguments{ +\item{...}{arguments} +} +\description{ +Code to use the hesim package inline. Not directly called by the user. +} +\examples{ +library(Rcpp) +sourceCpp(code=" +// [[Rcpp::depends(hesim)]] +// [[Rcpp::depends(RcppArmadillo)]] +#include +// [[Rcpp::export]] +double test_inline_gengamma(double mu, double sigma, double Q) { + hesim::stats::gengamma gg(mu, sigma, Q); + return gg.random(); +}") +set.seed(12345) +test_inline_gengamma(1.0, 1.0, 1.0) +} +\keyword{internal}