Skip to content

Instantly share code, notes, and snippets.

@slwu89
Created September 1, 2017 05:04
Show Gist options
  • Save slwu89/f90f5109eb72c76f058062547a8b9250 to your computer and use it in GitHub Desktop.
Save slwu89/f90f5109eb72c76f058062547a8b9250 to your computer and use it in GitHub Desktop.
C in Rcpp
#include <Rcpp.h>
using namespace Rcpp;
// C code with Rcpp; basic example
// [[Rcpp::export]]
extern "C" SEXP rngScopeCppScalar() {
NumericVector x(4);
RNGScope rngScope;
x[0] = R::runif(0,1);
x[1] = R::rnorm(0,1);
x[2] = R::rt(5);
x[3] = R::rbeta(1,1);
return wrap(x);
}
// [[Rcpp::export]]
RcppExport SEXP helloB2() {
Rcpp::StringVector result(1);
result[0] = "Hello World!";
return(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment